How to move C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\master.mdf to G:\Data\MSSQL13.MSSQLSERVER\MSSQL\DATA\master.mdf

Avyayah 1,291 Reputation points
2020-10-24T20:08:30.87+00:00

I have all system databases in C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\master.mdf. How do I move the system databases to G:\Data\MSSQL13.MSSQLSERVER\MSSQL\DATA\master.mdf? Will it cause any issues. I have one database that is existing in the current sqlserver where the datafile is in G:\Data\x.mdf

SQL Server | Other
{count} votes

Answer accepted by question author
  1. Avyayah 1,291 Reputation points
    2020-10-26T13:44:41.6+00:00

    @Shashank Singh , used the below command to move the files. Deleted all tempdb datafles,log files and ndf files.

    USE master;
    GO
    ALTER DATABASE tempdb
    MODIFY FILE (NAME = tempdev, FILENAME = 'F:\Data\MSSQL13.MSSQLSERVER\MSSQL\DATA\ tempdb.mdf');
    GO

    ALTER DATABASE tempdb
    MODIFY FILE (NAME = templog, FILENAME = 'E:\Log\MSSQL13.MSSQLSERVER\MSSQL\DATA\ templog.ldf');
    GO

    All temp files were created:

    SELECT name, physical_name AS CurrentLocation, state_desc
    FROM sys.master_files
    WHERE database_id = DB_ID('tempdb');
    GO

    name CurrentLocation state_desc
    tempdev F:\Data\MSSQL13.MSSQLSERVER\MSSQL\DATA\tempdb.mdf ONLINE
    templog E:\Log\MSSQL13.MSSQLSERVER\MSSQL\DATA\templog.ldf ONLINE
    temp2 E:\Log\MSSQL13.MSSQLSERVER\MSSQL\DATA\tempdb_mssql_2.ndf ONLINE
    temp3 E:\Log\MSSQL13.MSSQLSERVER\MSSQL\DATA\tempdb_mssql_3.ndf ONLINE
    temp4 E:\Log\MSSQL13.MSSQLSERVER\MSSQL\DATA\tempdb_mssql_4.ndf ONLINE

    .ndf files did not exist prior to moving the system databases so my question was any reason why it was generated? Will the .ndf files grow?


9 additional answers

Sort by: Most helpful
  1. Avyayah 1,291 Reputation points
    2020-10-26T14:49:41.8+00:00

    @tibor_karaszi@hotmail.com

    After executing query for both current and template state got the same output:

    db_name_ file_id name physical_name size_MB type_desc growth max_size_MB
    tempdb 1 tempdev F:\Data\MSSQL13.MSSQLSERVER\MSSQL\DATA\tempdb.mdf 8 ROWS 64 MB 0
    tempdb 3 temp2 E:\Log\MSSQL13.MSSQLSERVER\MSSQL\DATA\tempdb_mssql_2.ndf 8 ROWS 64 MB 0
    tempdb 4 temp3 E:\Log\MSSQL13.MSSQLSERVER\MSSQL\DATA\tempdb_mssql_3.ndf 8 ROWS 64 MB 0
    tempdb 5 temp4 E:\Log\MSSQL13.MSSQLSERVER\MSSQL\DATA\tempdb_mssql_4.ndf 8 ROWS 64 MB 0
    tempdb 2 templog E:\Log\MSSQL13.MSSQLSERVER\MSSQL\DATA\templog.ldf 8 LOG 64 MB 0

    Do I need to increase the size of tempdb? Will the current configuration cause any issues?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.