Copy data into another table
INSERT INTO table1 (col1, col2, col3)
SELECT column1, column2, column3
FROM table2
This is the proper way to do it:
INSERT INTO destinationTable
SELECT * FROM sourceTable
If both tables are truly the same schema:
INSERT INTO newTable
SELECT * FROM oldTable
Otherwise, you'll have to specify the column names (the column list for newTable
is optional if you are specifying a value for all columns and selecting columns in the same order as newTable
's schema):
INSERT INTO newTable (col1, col2, col3)
SELECT column1, column2, column3
FROM oldTable
Simple way if new table does not exist and you want to make a copy of old table with everything then following works in SQL Server.
SELECT * INTO NewTable FROM OldTable