Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sql query for inserting all records from one table to another existing table

Tags:

sql-server

I am using sql server as my database engine. I need a sql query, so that I can insert all records from one table to another existing table. Both tables are in same DB.

I need to use this query in my code.

like image 376
user310849 Avatar asked Dec 22 '22 13:12

user310849


2 Answers

 insert into destination_table ( field1, field2, field3, ... )
 select field1, field2, field3, ...
 from source_table
like image 68
Steve Mayne Avatar answered May 03 '23 07:05

Steve Mayne


Assuming all of the fields match (are in the same order and of the same type)

INSERT INTO TargetTable SELECT * FROM SourceTable
like image 39
Chris Shain Avatar answered May 03 '23 06:05

Chris Shain