SQL Server – Copy/Transfer Data between Databases

You can copy your previous tables/data’s to another table in same database or different database. To do that, you can use following codes;

INSERT INTO TargetTableName

(Column1, Column2)

SELECT Column1, Column2

FROM SourceTableName

To explain with an example;

In your previous project, you have a database named “Cars” and a table named “CarInfo” inside this database. You want to copy/transfer this table to your new project which includes a database named “Vehicles” and a table named “VehicleInfo”.

“CarInfo” table in “Cars” database

“VehicleInfo” table in “Vehicles” database

The codes you have to use are;

 INSERT INTO [Vehicles].[dbo].[VehicleInfo]  
 (   [vehiclePlateNo]  
 SELECT [carPlateNo]  
 FROM [Cars].[dbo].[CarInfo]  

When the code executed, you can see data’s in the source table added below the data’s in the target table

“VehicleInfo” table in “Vehicles” database

Bir cevap yazın

E-posta hesabınız yayımlanmayacak.