using tsql, sqlserver 2005.
I would like insert records from table table2 into an existing table table1 as easily as I could enter it into a new table table1 using:
select facilabbr, unitname, sortnum into table1 from table2
Any ideas?
From the Query Designer menu, point to Change Type, and then click Insert Results. In the Choose Target Table for Insert Results Dialog Box, select the table to copy rows to (the destination table).
The INSERT INTO SELECT statement copies data from one table and inserts it into another table. The INSERT INTO SELECT statement requires that the data types in source and target tables match. Note: The existing records in the target table are unaffected.
SELECT... INTO creates a new table in the default filegroup and inserts the resulting rows from the query into it. To view the complete SELECT syntax, see SELECT (Transact-SQL).
You can create one table from another by adding a SELECT statement at the end of the CREATE TABLE statement: CREATE TABLE new_tbl [AS] SELECT * FROM orig_tbl; MySQL creates new columns for all elements in the SELECT .
INSERT INTO table1
SELECT facilabbr, unitname, sortnum FROM table2
Assuming you just want to append and that the columns match up:
INSERT INTO Table1
SELECT facilabbr, unitname, sortnum FROM table2
If you want to replace and the columns still match:
Truncate Table1
INSERT INTO Table1
SELECT facilabbr, unitname, sortnum FROM table2
If you want to replace and the columns do not match:
DROP Table1
SELECT facilabbr, unitname, sortnum INTO Table1 FROM table2
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