How to do the equivalent of a 'Tsql select into', into an existing table

11,787

Solution 1

INSERT INTO table1
SELECT facilabbr, unitname, sortnum FROM table2

Solution 2

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

Solution 3

INSERT INTO TABLE1 T1 (T1.FIELD1, T1.FIELD2)
SELECT (T2.FIELD1, T2.FIELD2)
FROM TABLE2 T2 

should work.

Share:
11,787
Lill Lansey
Author by

Lill Lansey

I'm the web developer at work. I do everything from asking the users the right questions to creating the UI to setting up the SqlServer backend. What technology will I learn today?

Updated on June 07, 2022

Comments

  • Lill Lansey
    Lill Lansey about 2 years

    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?