Click here to Skip to main content
15,905,785 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.

how can i insert data from one database table(DB a1) into the same table but into another database table(DB a2)? i mean how can i specify this is a table from this database , and that table from that database?
Posted
Updated 3-Apr-18 20:06pm

You put the database name in your select statement.

Here[^].
 
Share this answer
 
Try :

SQL
SELECT *  INTO DestinationDatabase..DestTable FROM SourceDataBase..SourceTable  
--OR
INSERT INTO DestinationDataBase..DestTable SELECT * FROM SourceDataBase..SourceTable
 
Share this answer
 
Comments
mohammad ehsan 1-Aug-12 2:50am    
it has this error message:

An explicit value for the identity column in table 'DBMarashi..City' can only be specified when a column list is used and IDENTITY_INSERT is ON.
Om Prakash Pant 1-Aug-12 4:17am    
your table has identity column. you need to set the identity insert before inserting the data.

SET IDENTITY_INSERT dbo.City ON
GO

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900