views:

761

answers:

11

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?

+2  A: 

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

dimarzionist
+1  A: 

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.

X-Cubed
A: 

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

+7  A: 

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.

Rob Conery
By far the easiest as long as you have enough disk space to copy both mdf and ldf.
Scott Saad
sorry rob -- i think he needs a scripted approach, not a point n click approach.
Leon Bambrick
This is a good answer, but I think I agree withe Leon, a script is better.
ryan_s
Nice one Leno - totally agree
Rob Conery
sp_detach_db and sp_attach_db. It need not be point and click.
Ian Boyd
+6  A: 

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
Leon Bambrick
+2  A: 

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.

stephbu
Permissions, users and groups are good points. I'd give you an up-mod but I don't have the reputation...
ryan_s
yeah I've had my figures burnt transferring database where role members were (invalid) unregistered logins or domain members from another domain.
stephbu
A: 

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.

Kevin Sheffield
+2  A: 

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.

MotoWilliams
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
+1  A: 

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.

Mike L
A: 

Check those links:

YordanGeorgiev
A: 

Another one to check out that is quick and simple:

Simple SQL BULK Copy

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

Doug