Home > Mobile >  How to copy all tables from one database to another in SQL Server?
How to copy all tables from one database to another in SQL Server?

Time:06-15

I have created a database in SQL Server named "devdatabase" and another named "pocdatabase". Both of these databases have the same tables but only devdatabase has data populated in the tables. What is the best way to populate pocdatabase with the same data in the devdatabase tables?

CodePudding user response:

It depends on how many tables there are and only if you want the data in the tables or to copy other objects. If there are not hundreds of tables I would use append queries.

INSERT INTO DestinationDB.dbo.tableName SELECT * FROM SourceDB.dbo.SourceTable
INSERT INTO pocdatabase.dbo.tableName SELECT * FROM devdatabase.dbo.tableName

DestinationDB="pocdatabase" SourceDB="devdatabase" I assumed that the table names are identical. If you have a lot of tables so the above method is tedious then you could backup the "devdatabase" then restore the backup in "pocdatabase".

CodePudding user response:

Using SQL replication or data compare with other tools. ex: Redgate SQL Data Compare.

  • Related