How to: Attach a Database (SQL Server Management Studio)
Attaching a database places it in exactly the same state that it was in when it was detached.
This topic contains the following sections:
File access permissions are set during a number of database operations, including detaching or attaching a database. For information about file permissions that are set whenever a database is detached and attached, see Securing Data and Log Files.
We recommend that you do not attach or restore databases from unknown or untrusted sources. Such databases could contain malicious code that might execute unintended Transact-SQL code or cause errors by modifying the schema or the physical database structure. Before you use a database from an unknown or untrusted source, run DBCC CHECKDB on the database on a nonproduction server and also examine the code, such as stored procedures or other user-defined code, in the database.
For more information about attaching databases and information about changes that are made to metadata when you attach a database, see Detaching and Attaching Databases.
To attach a database
In SQL Server Management Studio Object Explorer, connect to an instance of the Microsoft SQL Server Database Engine, and then expand that instance.
Right-click Databases and click Attach.
In the Attach Databases dialog box, to specify the database to be attached, click Add; and in the Locate Database Files dialog box, select the disk drive where the database resides and expand the directory tree to find and select the .mdf file of the database; for example:
C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\AdventureWorks_Data.mdf
Trying to select a database that is already attached generates an error.
Optionally, to specify a different name for the database to attach as, enter the name in the Attach as column of the Attach Databases dialog box.
Optionally, change the owner of the database by selecting a different entry in the Owner column.
When you are ready to attach the database, click OK.
A newly attached database is not displayed in the Databases node of Object Explorer until the view is refreshed. To refresh the view at any time, click in Object Explorer, and then click Refresh on the View menu.