24

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?

11 Answers 11

49

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
1
15

Maybe the easiest is to detach/reattach. Right-click in the server manager on the DB, tasks --> detach. Then copy the MDF/LDF files to the new server and then reattach by clicking on the server icon and tasks-->attach. It will ask you for the MDF file - make sure the name etc is accurate.

6
  • By far the easiest as long as you have enough disk space to copy both mdf and ldf.
    – Scott Saad
    Sep 17, 2008 at 3:35
  • sorry rob -- i think he needs a scripted approach, not a point n click approach. Sep 17, 2008 at 3:37
  • This is a good answer, but I think I agree withe Leon, a script is better.
    – ryan_s
    Sep 17, 2008 at 3:46
  • 2
    sp_detach_db and sp_attach_db. It need not be point and click.
    – Ian Boyd
    Jun 30, 2009 at 18:00
  • 2
    Caveat, of course, is that you have to bring down the source. That doesn't fit many scenarios that I've seen this question being asked (production data to development data, hot standby, etc.) Oct 19, 2011 at 8:32
4

In order of ease

  • stop server/fcopy/attach is probably easiest.
  • backup/restore - can be done disconnected pretty simple and easy
  • transfer DTS task - needs file copy permissions
  • replication - furthest from simple to setup

Things to think about permissions, users and groups at the destination server esp. if you're transferring or restoring.

2
  • Permissions, users and groups are good points. I'd give you an up-mod but I don't have the reputation...
    – ryan_s
    Sep 17, 2008 at 3:45
  • yeah I've had my figures burnt transferring database where role members were (invalid) unregistered logins or domain members from another domain.
    – stephbu
    Sep 17, 2008 at 9:15
4

There are better answers already but this is an 'also ran' because it is just another option.

For the low low price of free you could look at the Microsoft SQL Server Database Publishing Wizard. This tool allows you to script the schema, data or data and schema. Plus is can be run from a UI or command line <- think CI process.

1
  • This is how i would do it... the tool is a life saver as it copies schema and data into a script - even for blob objects
    – Doug
    Jan 14, 2010 at 5:55
2

Backup -> Restore is the simplest, if not to use the replication.

2

If you use the Backup/Restore solution you're likely to have orphaned users so be sure to check out this article<microsoft> on how to fix them.

2

Another one to check out that is quick and simple:

Simple SQL BULK Copy

http://projects.c3o.com/files/3/plugins/entry11.aspx

1

Backup the databases using the standard SQL backup tool in Enterprise Manager, then when you restore on the second server you can specify the name of the new database.

This is the best way to maintain the schema in its entirety.

0

use backups to restore the databases to the new server with the new names.

0

Redgate SQL Compare and SQL Data Compare. The Comparison Bundle was by far the best investment a company I worked for ever made. Moving e-training content was a breeze with it.

0

Check those links:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.