Search code examples
sql-serverselect-into

SQL Server 'select * into' versus 'insert into ..select *


Say table1 and table2 already exist, is there any difference between these queries

query1 :-

select * into table1 from table2 where 1=1

query2: -

insert into table1 select * from table2

Solution

  • The select * into table1 from table2 where 1=1 creates table1 and inserts the values of table2 in them. So, if the table is already created that statement would give an error.

    The insert into table1 select * from table2 only inserts the values of table2 in table1.