使用tsql,sqlserver 2005.
我想将表table2中的记录插入到现有表table1中 我可以使用:
轻松地将其输入到新表table1中select facilabbr, unitname, sortnum into table1 from table2
有什么想法吗?
答案 0 :(得分:27)
INSERT INTO table1
SELECT facilabbr, unitname, sortnum FROM table2
答案 1 :(得分:12)
假设您只想追加并且列匹配:
INSERT INTO Table1
SELECT facilabbr, unitname, sortnum FROM table2
如果您想替换且列仍匹配:
Truncate Table1
INSERT INTO Table1
SELECT facilabbr, unitname, sortnum FROM table2
如果要替换且列不匹配:
DROP Table1
SELECT facilabbr, unitname, sortnum INTO Table1 FROM table2
答案 2 :(得分:5)
INSERT INTO TABLE1 T1 (T1.FIELD1, T1.FIELD2)
SELECT (T2.FIELD1, T2.FIELD2)
FROM TABLE2 T2
应该有用。