How to Attach and Detach a Database in SSMS
This tutorial will demonstrate how to detach a database from SQL server and how to attach a new database from database file.
Detach: The database will be removed from the SQL server.
Attach: There will be a new database in the SQL server.
2 Run the SQL Server Management Studio from the Start Menu
3 Detach the Database
3.1 Connect to the SQL Server
3.2 Choose the database
3.3 Right-click on the database. In this example, the example used is named “test”
3.4 Detach the database
3.5 Detach Successful
When your database has disappeared from the database list, you will know that it has been detached successfully
4 Attach Database
4.1 Copy your database file to the specific folder.
(Most likely it’s in C:\Program Files\Microsoft SQL Server\MSSQL\DATA\)
4.2 Right-click on the database and choose “Attach”
4.3 Click “Add”
4.4 Find the .mdf file of the database
4.5 Click “OK” to attach it to the database
4.6 Attach Successful
If the attach operation is successful, your database will show up in the database list.
4.7 Create a User
4.8 Choose a SQL Server Authentication and Setup Password
4.9 How to Perform User Mapping to Authorize a User to Use a Certain Database
4.9.1 Choose a User
4.9.2 User Mapping
Choose the database that this user can access. In this case, the database name is called “test”. Choose the database role membership for this user. In this example, db_owner and public is used.