How to move MSSQL Database to another drive

Posted by

– Check which database is using the old drive. This can be done with the following query.

SELECT name, physical_name AS CurrentLocation FROM sys.master_files

– Write down the output and check which DBs are placed on the old drive.
– Set your database offline with the following query:

ALTER DATABASE database_name SET OFFLINE;  

– Move your physical DB files to your new location. Which given in the query above.
– Modify the following query to your database variables, and run it.

ALTER DATABASE database_name MODIFY FILE ( NAME = logical_name, FILENAME = 'new_path\os_file_name.mdf');

– Set your database online with the following query.

ALTER DATABASE database_name SET ONLINE;  

– Check with the first query if the replacement is successful.

Leave a Reply

Your email address will not be published. Required fields are marked *