

- SQL SERVER MANAGEMENT STUDIO CHANGE DEFAULT FILE LOCATION HOW TO
- SQL SERVER MANAGEMENT STUDIO CHANGE DEFAULT FILE LOCATION UPDATE
- SQL SERVER MANAGEMENT STUDIO CHANGE DEFAULT FILE LOCATION CODE
- SQL SERVER MANAGEMENT STUDIO CHANGE DEFAULT FILE LOCATION PROFESSIONAL
- SQL SERVER MANAGEMENT STUDIO CHANGE DEFAULT FILE LOCATION FREE
Nupur Dave is a social media enthusiast and an independent consultant.
SQL SERVER MANAGEMENT STUDIO CHANGE DEFAULT FILE LOCATION FREE
If you need help with any SQL Server Performance Tuning Issues, please feel free to reach out at is also a CrossFit Level 1 Trainer (CF-L1) and CrossFit Level 2 Trainer (CF-L2).
SQL SERVER MANAGEMENT STUDIO CHANGE DEFAULT FILE LOCATION PROFESSIONAL
Pinal is an experienced and dedicated professional with a deep commitment to flawless customer service.

To freely share his knowledge and help others build their expertise, Pinal has also written more than 5,500 database tech articles on his blog at. Pinal has authored 13 SQL Server database books and 40 Pluralsight courses. He holds a Masters of Science degree and numerous database certifications. Pinal Dave is an SQL Server Performance Tuning Expert and independent consultant with over 17 years of hands-on experience. What are the best practices do you follow with regards to default file location for your database? I am interested to know them.
SQL SERVER MANAGEMENT STUDIO CHANGE DEFAULT FILE LOCATION CODE
You can also do the same with T-SQL and here is the T-SQL code to do the same.ĮXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'DefaultData', REG_SZ, N'F:\DATA'ĮXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'DefaultLog', REG_SZ, N'F:\DATA' All the future database created after the setting is changed will go to this new location. You can change the default location of the database files. Go to Right Click on Servers > Click on Properties > Go to the Database Settings screen To change the default location of the SQL Server Installation follow the steps mentioned below: This will not impact any database created before the change, it will only affect the default location of the database created after the change. If you have already installed SQL Server there is an easy way to solve this problem. The ideal scenario would be to specify this default location of the database files when SQL Server Installation was performed. This way we do not have to change the location of the database after it is created at different locations.
SQL SERVER MANAGEMENT STUDIO CHANGE DEFAULT FILE LOCATION HOW TO
I had mentioned that we will discuss how to change the default location of the database. Or you could specify the data and log file locations when creating your database, a good habit that everyone should have! I still prefer to set the default values, in order to help those that might not have good habits formed yet.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. You will find the option for this on the ‘Database Engine Configuration’ screen as follows:īy doing this during the installation you can avoid the need to restart the service at a later date to make this simple change. I’d suggest that you configure these directories when you are installing SQL Server. Run that, restart the instance, and then run our create database script again.
SQL SERVER MANAGEMENT STUDIO CHANGE DEFAULT FILE LOCATION UPDATE
, N'SoftwareMicrosoftMSSQLServerMSSQLServer'ĮXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE' CREATE DATABASE TestFileLoc GO SELECT filename FROM sys.sysaltfiles WHERE name LIKE 'TestFileLoc' Which returns the locations of our data and log files, which we see are the defaults: Changing the default is easy enough, we can just update the file locations inside of SSMS. In fact, after you make your change in the SSMS, hit the little button at the top that says ‘Script’ and check out what is being done behind the scenes: EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE' The reason why is because the default locations are read from registry values. Turns out that setting the default database locations requires you to restart the SQL instance in order for those changes to take effect. Press OK, and we’ll run our create database script again (don’t forget to drop the original database first) to find this result set: Let’s update the setting to point to the new directories: It’s also important to note that storing your data and log files on the same disk is not a recommended practice. These changes will only apply to new databases created from this point forward. It is important to note that updating these locations will NOT migrate the current data and log files to the new directories. I will create two new folders (C:SQLData and C:SQLLogs) to store the data and log files for new databases. Which returns the locations of our data and log files, which we see are the defaults:Ĭhanging the default is easy enough, we can just update the file locations inside of SSMS. If we create a simple database we can verify that the files are written to these directories: CREATE DATABASE TestFileLoc You can see these properties for yourself by right-clicking on the instance name inside of SQL Server Management Studio (SSMS) and navigating to the ‘Database Settings’ tab: When you create a database in SQL Server and do not specify a file location for your data and log files SQL Server will rely on the default locations as defined in the server properties.
