I have a database "temp" with table "A". I created new database "temp2". I want to copy table "A" from "temp" to a new table in "temp2" . I tried this statement but it says I have incorrect syntax, here is the statement:
CREATE TABLE B IN 'temp2'
AS (SELECT * FROM A IN 'temp');
Here is the error:
Msg 156, Level 15, State 1, Line 2 Incorrect syntax near the keyword 'IN'. Msg 156, Level 15, State 1, Line 3 Incorrect syntax near the keyword 'IN'.
Anyone knows whats the problem?
Thanks in advance,
Greg
If you would like to create a new table based on the structure and data from another table, you can use the SELECT INTO clause. First, write a SELECT clause followed by a list of columns (in our example: id , name , and price ) from the existing table (in our example: product ).
A copy of an existing table can be created using a combination of the CREATE TABLE statement and the SELECT statement. The new table has the same column definitions. All columns or specific columns can be selected.
A copy of an existing table can also be created using CREATE TABLE . The new table gets the same column definitions. All columns or specific columns can be selected. If you create a new table using an existing table, the new table will be filled with the existing values from the old table.
Using SQL Server Management StudioOpen the table with columns you want to copy and the one you want to copy into by right-clicking the tables, and then clicking Design. Click the tab for the table with the columns you want to copy and select those columns.
I've not seen that syntax before. This is what I normally use.
SELECT *
INTO temp2.dbo.B
FROM temp.dbo.A
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With