Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How best to copy entire databases in MS SQL Server?

Tags:

I need to copy about 40 databases from one server to another. The new databases should have new names, but all the same tables, data and indexes as the original databases. So far I've been:

1) creating each destination database
2) using the "Tasks->Export Data" command to create and populate tables for each database individually
3) rebuilding all of the indexes for each database with a SQL script

Only three steps per database, but I'll bet there's an easier way. Do any MS SQL Server experts out there have any advice?

like image 784
ryan_s Avatar asked Sep 17 '08 03:09

ryan_s


People also ask

How to copy a database on the same SQL Server?

How to copy a database on the same SQL server. 1 1. step: Make a back up of your source database. Click on the desired database and choose “Backup” under tasks. 2 2. step: Use copy only or use a full backup. 3 3. step: Use “Restore” to create a new database. 4 4. step: Choose the copy-only backup and choose a new name.

How many steps to copy 40 databases from one server to another?

I need to copy about 40 databases from one server to another. The new databases should have new names, but all the same tables, data and indexes as the original databases. So far I've been: Only three steps per database, but I'll bet there's an easier way. Do any MS SQL Server experts out there have any advice?

Can I do a DB restore from one database to another?

If you can login to both servers (the Express and the 05 Server) using SQL Server Management Studio then you can do a DB Restore from one database to the other. No need for backup files at all.

How to copy tables from source to destination in SQL Server?

Another method that can be used to copy tables from the source database to the destination one is the SQL Server Export and Import wizard, which is available in SQL Server Management Studio.


1 Answers

Given that you're performing this on multiple databases -- you want a simple scripted solution, not a point and click solution.

This is a backup script that i keep around. Get it working for one file and then modify it for many.

(on source server...) BACKUP DATABASE Northwind   TO DISK = 'c:\Northwind.bak'  (target server...) RESTORE FILELISTONLY   FROM DISK = 'c:\Northwind.bak'  (look at the device names... and determine where you want the mdf and ldf files to go on this target server)  RESTORE DATABASE TestDB   FROM DISK = 'c:\Northwind.bak'   WITH MOVE 'Northwind' TO 'c:\test\testdb.mdf',   MOVE 'Northwind_log' TO 'c:\test\testdb.ldf' GO 
like image 66
Leon Bambrick Avatar answered Sep 30 '22 10:09

Leon Bambrick