Microsoft® SQL Server® 2012 Bible

(Ben Green) #1

624


Part V: Enterprise Data Management


FIGURE 23-6
Results of the script generation process.

Detaching and Attaching


Although it is often overlooked, one of the easiest ways to move a database from one com-
puter to another is to detach the database, copy the fi les, and attach the database to SQL
Server on the destination computer.

For developers who frequently move databases between notebooks and servers, this is the
recommended method. Detaching a database effectively deletes the database from SQL
Server’s awareness but leaves the fi les intact. The database must have no current connec-
tions, no snapshots, and not be replicated or mirrored if it is to be detached. Additionally,
system databases or databases that are listed as being suspect may not be detached. In
order to attach a database, you need at least CREATE DATABASE, CREATE ANY DATABASE,
or ALTER ANY DATABASE permissions on the instance. To be able to detach a database,
membership in the db_owner fi xed database role is required.

c23.indd 624c23.indd 624 7/31/2012 9:25:21 AM7/31/2012 9:25:21 AM


http://www.it-ebooks.info
Free download pdf