How to do the equivalent of a 'Tsql select into', into an existing table
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开发者_如何学Python, sortnum into table1 from table2
Any ideas?
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
INSERT INTO TABLE1 T1 (T1.FIELD1, T1.FIELD2)
SELECT (T2.FIELD1, T2.FIELD2)
FROM TABLE2 T2
should work.
精彩评论