Sunday, April 16, 2017

Insert Data From one Database Table to another Database Table on Same Server

Today we are going to learn how to insert data from one database table to another database table. I am going to write a separate post in coming days to insert records from different database servers.
So without wasting time let’s have a look at the query to insert records from one DB table to another DB table on a same server.

Insert into [Database Name].[Schema].[Table Name]
Select * from [Database Name].[Schema].[Table Name]

If you want to pick specific columns then you will write this query like this

Insert into [Database Name].[Schema].[Table Name](Column1,Column2)
Select Column1, Column2 from [Database Name].[Schema].[Table Name]

For example you are moving customer table’s data from Northwind database to AdventureWorks database on the same server/machine/computer then your query will be

Insert into [AdventureWorks].[dbo].[Customer]
Select * from [Northwind].[dbo].[Customer]

Comments and Suggestions are Always Welcome!

No comments:

Post a Comment