Friday, May 20, 2011

How to: Move a Database Using Detach and Attach (Transact-SQL)

You can move a detached database to another location and re-attach it to the same or a different server instance.

Attach the moved database and, optionally, its log by executing the following Transact-SQL statements:

USE master;
GO
CREATE DATABASE MyAdventureWorks
ON (FILENAME = 'C:\MySQLServer\AdventureWorks2008R2_Data.mdf'),
(FILENAME = 'C:\MySQLServer\AdventureWorks2008R2_Log.ldf')
FOR ATTACH;
GO

For a production database, place the database and transaction log on separate disks.

Enjoy on this !

No comments: