﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Administering / SQL Server 2005  / default data/log file location / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Thu, 23 May 2013 10:09:06 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: default data/log file location</title><link>http://www.sqlservercentral.com/Forums/Topic525288-146-1.aspx</link><description>Data:[code]-- ***************************************************************************-- nvarchar(4000) = dbo.fn_SQLServerDataDir()-- ***************************************************************************IF OBJECT_ID('SQLServerDataDir_fn','FN') IS NOT NULL DROP FUNCTION SQLServerDataDir_fnGOcreate function dbo.SQLServerDataDir_fn()returns nvarchar(4000)asbegindeclare @rc int,@dir nvarchar(4000)exec @rc = master.dbo.xp_instance_regread N'HKEY_LOCAL_MACHINE',N'Software\Microsoft\MSSQLServer\MSSQLServer',N'DefaultData', @dir output, 'no_output'if (@dir is null)beginexec @rc = master.dbo.xp_instance_regread N'HKEY_LOCAL_MACHINE',N'Software\Microsoft\MSSQLServer\Setup',N'SQLDataRoot', @dir output, 'no_output'select @dir = @dir + N'\Data'endreturn @dirend[/code]Log[code]-- ***************************************************************************-- nvarchar(4000) = dbo.SQLServerLogDir_fn()-- ***************************************************************************IF OBJECT_ID('SQLServerLogDir_fn','FN') IS NOT NULL DROP FUNCTION SQLServerLogDir_fnGOcreate function dbo.SQLServerLogDir_fn()returns nvarchar(4000)asbegindeclare @rc int,@dir nvarchar(4000)exec @rc = master.dbo.xp_instance_regread N'HKEY_LOCAL_MACHINE',N'Software\Microsoft\MSSQLServer\MSSQLServer',N'DefaultLog', @dir output, 'no_output'if (@dir is null)beginexec @rc = master.dbo.xp_instance_regread N'HKEY_LOCAL_MACHINE',N'Software\Microsoft\MSSQLServer\Setup',N'SQLDataRoot', @dir output, 'no_output'select @dir = @dir + N'\Data'endreturn @dirend[/code]</description><pubDate>Fri, 27 Jun 2008 13:39:40 GMT</pubDate><dc:creator>Adam Bean</dc:creator></item><item><title>default data/log file location</title><link>http://www.sqlservercentral.com/Forums/Topic525288-146-1.aspx</link><description>I'm struggling to find a way to get the default data and log locations using t-sql. Is there a way to either do this without reading the registry? if not, does anyone have a script that will grab those values from the registry regardless of default/named instance?I have one that works well for default instance, but I need one I can drop on any server and have it grab those values correctly.Any help would be greatly appreciated.Thanks</description><pubDate>Fri, 27 Jun 2008 12:51:53 GMT</pubDate><dc:creator>Adam Angelini</dc:creator></item></channel></rss>