Detaching a database means separating the database from the SQL Server instance, but not deleting the database's file and transaction log files, so that the database can be attached to other instances
Unable to detach the state of the database:
1. The database has been replicated and published
2. Database snapshots exist in the database
3. The database is in an unknown state
Attaching a database refers to attaching a database other than the current instance to the current instance. When you attach a database, both the. mdf and. ndf files for the database should be available. You need to specify the current database file location if the attached database file is different from the location where the database was created or when it was last attached. In the process of attaching a database, if there is no log file, a new log file is created
How it works (in Microsoft SQL Server Management Studio):
Detach: Select the database that needs to be detached, right-task-detach
Additional: Select ' Database ', right-attach, locate the. mdf file that needs to attach the database for additional operations
SQL Server detach and attach database