Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sql server 2008: setting default location for mdf/ldf

When I create a new database, by default the files are saved to c:\program files... but I would like them by default to be saved into a different location WITHOUT having to adjust anything. Is there a way to have this done by default?

Perhaps there's some stored system procedure that I would have to change?

like image 583
Alex Gordon Avatar asked Oct 29 '10 16:10

Alex Gordon


People also ask

Where are MDF and LDF files stored?

Microsoft SQL Server stores two types of data files in default directories on respective systems, which are known as Master Database Files and Log Database Files, and abbreviated as MDF and LDF data files. Both these files are primarily available in the SQL Server environment.


1 Answers

In SSMS, right click on the server and choose "Properties". On the "Database Settings" page of the Server Properties window, specify your new locations for data and log files.

alt text

You could also do this with T-SQL by writing directly to the registry:

USE [master]
GO
EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'DefaultData', REG_SZ, N'E:\YourData'
GO
EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'DefaultLog', REG_SZ, N'E:\YourLogs'
GO 
like image 134
Joe Stefanelli Avatar answered Oct 08 '22 23:10

Joe Stefanelli