Microsoft® SQL Server 2012 Unleashed
by Ray Rankins, Paul T. Bertucci, Chris Gallelli, Alex T. Silverstein
Detaching and Attaching Databases
A convenient way to move or copy database files is to detach and attach databases. Detaching database files removes the database from an instance of SQL Server but leaves the database files intact. After the database is detached, the files associated with the database (that is, .mdf, .ndf, and .ldf files) can be copied or moved to an alternate location. You can then reattach the relocated files by using the CREATE DATABASE command with the FOR ATTACH option.
Tip
The process of detaching and attaching a database is extremely fast. It is therefore a good alternative to use BACKUP and RESTORE when you’re copying a database to another location. The catch with detaching a database is that all users must be disconnected ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access