Unable to copy a table into a new table [closed] - sql

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 2 years ago.
Improve this question
I'm trying to clone a table schema and data into a new table, this is what I'm doing:
SELECT * INTO 'ECO7053__settings' FROM base__settings
I keep getting the Undeclared Variable error
EDIT: Also to complete the questions, is this the correct approach? I need to store data for different users; is it better to add an uID field on my tables and filter by that or rather what I'm trying to do, and have different tables one for each user with a prefix? In the example the uID would be 7053 what would be the correct way to handle this situation?

CREATE TABLE ECO7053__settings LIKE base__settings;
to copy the table schema and indices. Then
INSERT INTO ECO7053__settings SELECT * FROM base__settings;
to copy the data.

Use:
SHOW CREATE TABLE base__settings
Copy the create statement and change base__settings into ECO7053__settings (do a search and replace)
Then run
INSERT INTO ECO7053__settings
SELECT * FROM base__settings

Related

Is there a faster way to add new column data with hundreds of rows? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 11 months ago.
Improve this question
I have a decent-sized table 'countries' with about 10 columns. I recently added a new column to the table 'GDP' and I am entering the information per row using
UPDATE countries
SET GDP=(value)
WHERE name = (country);
I have 200 countries in this table. Is there a better way to update this information?
This project is from Khan Academy. We are asked to select a database and run queries on it. The data was pulled from https://gist.github.com/pamelafox/ad4f6abbaac0a48aa781
I am just making sure that there isn't a more efficient way of adding this information to the existing table 'countries' where the primary key is the name of the country.

SQL update field based on conditions of another field [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
Super noob here.
I want to update column AI_Amount to 0 whenever column Delete_Field = C.
When a customer leaves the delete_field gets updated to a C but the AI_Amount field will not zero out. How do I go about doing this?
I tried using the update clause but it says I don't have permission. I don't want to update the actual table just the query results.
I don't want to update the actual table just the query results.
You seem to want select, not update:
select
delete_field,
case when delete_field = 'C' then 0 else ai_amount end as ai_amount,
-- other columns here
from mytable

How would I add a row count that resets for each ID? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I need to add a column to a sql table that counts how many rows per ID. Some IDs may just have 1 result while others may have 3+.
What's the most efficient way to handle this?
In a query, you can use:
select t.*, count(*) over (partition by id) as cnt
from t;
This is probably the simplest method. You can wrap a view around this. You can also create a materialized view.
If you actually need a column, then you have two choices for keeping it up-to-date:
Triggers, to update the value each time a row is inserted, deleted, or updated.
A user-defined function and a computed column.

Does someone know how can I connect multi-DB-servers for clearing code or samples [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have found out a lot of messages from stack overflow but it is too much information to me , and I didn't see any clear code ,I wish I can use like as below URLs with easy way
Querying data by joining two tables in two database on different servers
Selecting data from two different servers in SQL Server
PS: sorry for all , maybe my English isn't very well ,so that I cannot understand or know , hopefully someone can give me a very simple code
This sample is very easy , hopefully it is you want
1.Data Source <=Server ip or ServerName
2.Initial Catalog <= DB Name
3.User ID <= Account ID
4.Password <= Account PWD
5.[*****].[dbo].[awards] <= which table you want to find out
SELECT *
FROM OPENDATASOURCE('SQLNCLI',
'Data Source=10.***.***.***;Initial Catalog=B2C**;User ID=****;Password="****"')
.[*****].[dbo].[awards]
PS: more detail you can see
https://msdn.microsoft.com/zh-tw/library/ms179856(v=sql.120).aspx
or Querying data by joining two tables in two database on different servers
or Selecting data from two different servers in SQL Server
it will be gave you more detail ways or methods

In Oracle SQL, how do I find where a column may be referenced using just queries? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have a specific column, called DELIVER_TO_LOCATION_ID , which is in a table called apps.po_requisition_lines_all
I need to dig into the database and derive the continent from the DELIVER_TO_LOCATION_ID ,
In SQL Developer I can't seem to find a way to do this .
any tips appreciated. thanks
You can use following command-
desc tableName
It'll give you description of table including every column in it having any constraints on it or not like primary key, reference key etc.