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 ...
Get Microsoft SQL Server 2014 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.