Thursday, May 09, 2024
Microsoft SQL Server

How to move model database files in SQL Server

Detailed steps on how to move model database files (mdf and ldf) from one location to another. This change requires a restart of your SQL Server Instance, so make sure to do this during a maintenance window.

  1. First find the model database files location which we want to move. To do that, execute the following query.
use master
go
select db_name(database_id) 'DatabaseName', name 'LogicalFileName',physical_name 'PhysicalFileName'
from sys.master_files
where database_id = db_id('model')
go

2. Now that you have the logical and physical file names, navigate to the new folder or drive where you have to move the files. That is., the destination folder or directory. Right click on the destination folder and give full access to the SQL Server service account.

3. Now update the new file locations in master database using the below query. This will update the new database files location for model database in the master database.

use master
go
alter database model
modify file (name = modeldev, filename = 'F:\MSSQL\NewLocation\model.mdf');
go
alter database model
modify file (name = modellog, filename = 'L:\MSSQL\NewLocation\modellog.ldf');
go

4. Stop your SQL Server Instance.

5. Now that the SQL Server Instance is stopped, move the files physically from old location to new location.

6. Once the files are moved, start your SQL Server Instance.

7. Run the below query to verify the new path of model database.

use master
go
select db_name(database_id) 'DatabaseName', name 'LogicalFileName',physical_name 'PhysicalFileName'
from sys.master_files
where database_id = db_id('model')
go

Click on the below link to learn more on moving other system databases and user databases in SQL Server.

Move User and System Databases in SQL Server

Back To Top
error: Content is protected !!