TSQL to get default location of database data and log files?

Published 08 January 08 05:37 AM | SQL Master 
By default the SQL Server database data & log files are created on the default data directory which is Program Files or based on where SQL binary files are installed.
 
In order to find what is the default location you can run following TSQL:

declare @SmoDefaultFile nvarchar(512)
exec master.dbo.xp_instance_regread N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\Microsoft SQL Server\MSSQL.1\MSSQLServer', N'DefaultData', @SmoDefaultFile OUTPUT

declare @SmoDefaultLog nvarchar(512)
exec master.dbo.xp_instance_regread N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\Microsoft SQL Server\MSSQL.1\MSSQLServer', N'DefaultLog', @SmoDefaultLog OUTPUT

SELECT ISNULL(@SmoDefaultFile,N'') AS [DefaultFile], ISNULL(@SmoDefaultLog,N'') AS [DefaultLog]

Comments

# SSQA.net - SqlServer-QA.net said on January 8, 2008 6:30 AM:

By default the SQL Server database data & log files are created on the default data directory which

# Other SQL Server Blogs around the Web said on January 8, 2008 6:34 AM:

By default the SQL Server database data & log files are created on the default data directory which

# Default Data location | keyongtech said on January 18, 2009 10:19 AM:

PingBack from http://www.keyongtech.com/2244354-default-data-location

Anonymous comments are disabled

About SQL Master

**__________________________________** SQL Server MVP, Sr. DBA & industry expert. - Knowledge is of two kinds. We know a subject ourselves or we know where we can find information on it. It is also a power and you will gain by sharing it.

Search

Go

This Blog

«January 2008»
SMTWTFS
303112345
6789101112
13141516171819
20212223242526
272829303112
3456789

Syndication