Finding Default Database Path

  • Hi

    How would one find the default database path for SQL Server 2005? Is there an environment variable that one could use? Currently our create database statement contains:

    FILENAME = 'c:\program files\microsoft sql server\mssql\data\X.mdf',

    What is a good way to genericise this? e.g. "$DEFAULT_DB_PATH$\X.mdf"

    Thank you

  • You need to query the registry.

    DECLARE

    @DefData nvarchar(200)

    EXEC

    master.dbo.xp_instance_regread N'HKEY_LOCAL_MACHINE',N'Software\Microsoft\MSSQLServer\MSSQLServer',N'DefaultData', @DefData output

    SELECT

    @DefData

    Markus

    [font="Verdana"]Markus Bohse[/font]

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply