Server Settings – Part 3

Tonight, I will be talking about default database paths that a DBA can change either manually or programatically.

The automated process is to use undocumented extended system stored procedures to read from and write to the registry. The manual process is to use the Server Properties dialog box in SQL Server Management Studio (SSMS).

I am going to start with the database settings page that contains the default data file and log file directories. This setting determines where the data files (*.mdf, *.ndf) and log files (*.ldf) are stored.

Just enter the new directories in the database settings page and press the okay button to save. The configured values depict what is the stored value to use in the future. If a change requires the database engine to be restarted, the configured value will not equal the running value.

The TSQL snippets below use the xp_regread and xp_regwrite extended system stored procedures. There are three different places in the registry to read the default data and log directories.

If the default paths have never been changed since installation, the setting is stored in the registry under the SQLDataRoot key. The actual full key is dependent upon the instance, version and edition of SQL Server.

If changes have been made for the default data or log file directories, use the DefaultData and DefaultLog registry key respectively for reading and writing. The TSQL snippet below reads the current settings from the registry.

I want standardize my servers to have all default directories stored underneath the C:\MSSQL\ directory. The TSQL snippet below writes the new settings to the registry for default data and log file directories.

Last but not least, the default location for backup files (*.bak, *.trn) can not be set in the Server Properties dialog box in SSMS. However, it is stores in the registry under the BackupDirectory key. The TSQL snipet below reads the current setting.

To complete the example, the default backup directory is changed to conform to the new standard.

A new backup task was started on the Boy Scouts of America (BSA) sample database that I have used in the past. The new default backup location is picked up by the dialog box in SSMS.

In summary, the xp_regread and xp_regwrite extended stored procedures can be used to change the default directory for data, log and backup files.

Related posts

10 Thoughts to “Server Settings – Part 3”

  1. very interesting topic , outstanding post.

  2. Hi there, just became aware of your blog through Google, and found that it is really informative. I’ll be grateful if you continue this in future. Many people will be benefited from your writing. Cheers!

  3. As a Newbie, I am permanently searching online for articles that can aid me. Thank you

  4. Don’t aim for success if you want it; just do what you love and believe in, and it will come naturally.

  5. Lovely website! I am loving it!! Will be back later to read some more. I am taking your feeds also

  6. I am thankful to find this website through google.

  7. I just couldn’t leave your website before letting you know that I actually enjoyed the useful details you offer to your visitors…

  8. Bookmarked this post and look forward to coming back again. Great job!

  9. Thank you for helping out, fantastic info.

  10. I appreciate all the work you all have put into your blog! I’m going to Tweet this out to my followers… Definitely worth repeating!

Leave a Comment