Attachment and Detachment of SQL Server Database

Separation 1. Use SSMS method
Select the database that needs to be detached, right-click, select the task, and then click Detach

Click OK

2. T-SQL method
- execute: execute
- sp_Detach_DB: Separated stored procedure (understood as a function)
- execute sp_Detach_Db '< Database Name
Execute sp_Detach_Db 'Table2'
Additional 1. Use SSMS method
Select the database, right-click, and click attach

Click to add

Find the location where the database files are stored, select the database that needs to be attached, and then click OK

Finally, click OK

2. T-SQL method
- Additional - sp_Attach_Db: Additional stored procedures
- exec sp_Attach_Db '< Database Name< The path where the database file is located
Exec sp_Attach_Db 'Table2', 'C: Program Files Microsoft SQL Server MSSQL15. MSSQLSERVER15 MSSQL DATA Table2. mdf'.