

In the detach database window, we put a check on Update Statistics. You can see the parameter = false in this query. The second script uses the sp_detach_db stored procedure in the master database. If it is enabled, you cannot access the database into single-user mode. Note: You should verify the AUTO_UPDATE_STATISTICS_ASYNC setting as well. We also have a checkbox drop connections to drop all connections for you before detaching the SQL database. You can review and close the connections manually. If you click on the active connections message, it gives prompt that you should close the existing connections: Also should look at the message column in the image below, a database has 6 active connections Here, we get the following information’s:ĭrop connections: We should have any existing connections to the database else SQL Server cannot detach it. It opens the detach database window, as shown below: Right-click on the desired database in SSMS and click on Tasks->Detach: In this method, we first detach the database from the source instance. Suppose we want to move these files to ‘C:\sqlshack\Demo’ folder. In the above screenshots, note that database files are in the default locations.

In the files section, you can also view files information: Using the GUI method, right-click on the database and properties. Run the sp_helpfile command in current database security context and save information separately:

We should collect the information about existing files, their locations before start moving a database. As you know, a SQL database might contain multiple data files(one primary and multiple secondary) and transaction log files. Planning is necessary before we move a database.

We can use the following steps for moving a database using detach ad attach method. Move a database using detach and attach method In this article, we will discuss the detach and attach method to move a SQL database. There are multiple ways to move a database such as backup & restore, take the database offline.
