SQL SERVER – Changing Default Installation Path for SQL Server

Earlier I wrote a blog post about SQL SERVER – Move Database Files MDF and LDF to Another Location and in the blog post we discussed how we can change the location of the MDF and LDF files after database is already created. I had mentioned that we will discuss how to change the default location of the database. This way we do not have to change the location of the database after it is created at different locations.

The ideal scenario would be to specify this default location of the database files when SQL Server Installation was performed. If you have already installed SQL Server there is an easy way to solve this problem. This will not impact any database created before the change, it will only affect the default location of the database created after the change.

To change the default location of the SQL Server Installation follow the steps mentioned below:

Go to Right Click on Servers >> Click on Properties >> Go to the Database Settings screen

Solarwinds

SQL SERVER - Changing Default Installation Path for SQL Server servprop1

You can change the default location of the database files. All the future database created after the setting is changed will go to this new location.

SQL SERVER - Changing Default Installation Path for SQL Server servprop2

You can also do the same with T-SQL and here is the T-SQL code to do the same.

USE [master] GO
EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'DefaultData', REG_SZ, N'F:\DATA'
GO
EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'DefaultLog', REG_SZ, N'F:\DATA'
GO

What are the best practices do you follow with regards to default file location for your database? I am interested to know them.

Reference : Pinal Dave (https://blog.sqlauthority.com)

Solarwinds
Previous Post
SQL SERVER – Beginning New Weekly Series – Memory Lane – #002
Next Post
SQL SERVER – Get Free Books on While Learning SQL Server 2012 Error Handling

Related Posts

15 Comments. Leave new

  • super …

    Reply
  • Very nice… easy way to change path…..

    Reply
  • Good overview, but unfortunately you haven’t tried to set the DB and Log location to an other than the system drive. In our situation I’ve configured the DB and Log location during the setup to point to S:\MSSQL\DATA and L:\MSSQL\LOGS respectively. Directories are indeed created, but when I put a mdf and ldf in the correct directory and want to attache that DB, I can only brows the c:\ drive.
    The MSSQLSERVER account and the account the SQL service is running with do have “Full control” on the S and L drive.
    I’ve not seen any post about others having the same probelem. Any suggestions?

    Reply
  • Nakul Vachhrajani
    November 18, 2012 8:48 pm

    Here’s an interesting little change that Microsoft made to the Backup/Restore wizard with respect to default file naming (it’s not related to default file path, but since we are relating to the backup/restore wizard in this post, I thought of adding my 2 cents :))

    MS Connect Case #668566 –

    Changes to backup/restore wizard:

    Reply
  • good info…….

    Reply
  • Good Info….

    Reply
  • How to get the same information through query, please help

    Reply
  • Vince De Mello
    August 19, 2013 3:49 pm

    Thanks for this article. It seems to imply that all FUTURE databases created after this setting will go to this new location. However I want to move all the existing databases to this new location as I am running out of disk space on the C drive partition. Do you know how this can be done? Can I simply copy everything over to the new location?

    Reply
    • Just use DETACH, then move the physical files (.mdf and .ldf) then use ATTACH to reattach the database from its new location.

      Reply
  • Sagar Chowdary
    April 5, 2015 9:01 am

    hai
    In my machine i have sql server 2005 in C drive,now i want chage that total Instance into D drive.Anyone plz tell me how to change sql server 2005 instance “Root directory” from C drive to D drive.

    Reply
    • You can detach and attach the database from C to D.
      For complete movement, you need to uninstall and reinstall SQL.

      Reply
  • I’m trying to install 2014 Standard edition (64bit) and dont seem able to prevent it from installing most of the application on the c drive – which runs out of space during the installation, how can i force SQL to install everything to the d drive?

    Reply
    • you can’t force EVERYTHING on d drive because C is system drive. Unless you make d drive as system drive, it won’t be possible.

      Reply
  • I have a server where SQL Server 2017 has been uninstalled and reinstalled. The first time I installed (SQL Server Express 2017, upgraded to Standard later), the database instance root was “D:\Program Files\Microsoft SQL Server\”. The new install is only letting me specify “C:\Program Files\Microsoft SQL Server\”; it is grayed out and cannot be modified.

    How can I resolve this short of reloading the entire server?

    Reply

Leave a Reply

Menu