Reputation: 3889
I have two identical databases on the same server. During a deployment process, I have data in tables in database A that need copied over to the tables in database B. What is the easiest way to programmatically accomplish this task?
EDIT:
Upvotes: 1
Views: 2689
Reputation: 15167
If the databases are in different servers:
exec sp_addlinkedserver ServerA
Insert Into DatabaseB.dbo.DestinationTable
Select * From ServerA.DatabaseA.dbo.SourceTable
Upvotes: 2
Reputation: 1328
Assuming that the tables don't have identity columns and belongs to the default (dbo) schema, try the TSQL insert query below;
Insert Into DatabaseB.dbo.DestinationTable
Select * From DatabaseA.dbo.SourceTable
If you have an identity column then execute statements below
SET IDENTITY_INSERT DatabaseB.dbo.DestinationTable ON
GO
Insert Into DatabaseB.dbo.DestinationTable
Select * From DatabaseA.dbo.SourceTable
GO
SET IDENTITY_INSERT DatabaseB.dbo.DestinationTable OFF
GO
Upvotes: 4