Microsoft® SQL Server® 2012 Bible

(Ben Green) #1

626


Part V: Enterprise Data Management


After the fi le is detached, the database disappears from the list of databases in
Management Studio. The fi les may then be copied or moved like regular fi les.

To reattach the database fi le, select Databases in the Management Studio console tree and
Tasks ➪ Attach from the action menu or context menu. The Attach Database dialog box, as
shown in Figure 23-8, simply offers a place to select the fi le and verify the fi le locations
and names.

FIGURE 23-8
The database may be reattached by means of Management Studio’s Attach Database tool.

In code, the database is detached by running the sp_detach_db system stored procedure.
The fi rst parameter is the database to be detached. A second optional parameter simply
turns off automatic updating of the index statistics. The following command detaches the
AdventureWorks sample database:

sp_detach_db 'AdventureWorks'

c23.indd 626c23.indd 626 7/31/2012 9:25:22 AM7/31/2012 9:25:22 AM


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