How to return the Drives assigned to the SQL instance.

  • Is there any why to query the SQL instance and return the Drive that the instance is using. Maybe return the default database file locations and substring the the drive letter, or any other way that someone may know.

    I know EXEC master.dbo.xp_fixeddrives returns all the drive letter on the physical box but I only want to return the drive letters that the instance is dependant on.

    I'm trying to make a dynamic dw load to return all theis information and because I have mulitiple instances of SQL I get the drive letters repeated if I use the EXEC master.dbo.xp_fixeddrives procedure.

    Any ideas?

  • I can think of two places you should look. The first query is for the database file locations and the second query is where the dll's are located.

    SELECT SUBSTRING(filename,1,1) as DRIVE, *

    FROM master.sys.sysaltfiles

    SELECT SUBSTRING(subsystem_dll,1,1) as DRIVE, *

    FROM msdb..syssubsystems

    WHERE subsystem_dll '[Internal]'

    This doesn't include any drives you may be sending backups to or log files. Are you concerned with those also?

  • This will dump all the MDF & LDF file drive letters to a table, then you can select distinct. Probably a better way though

    CREATE TABLE dbo.DBFileLocations

    (

    DBName nvarchar(50) NULL,

    Physical_Name nvarchar(260) NULL,

    Drive_Letter nchar(1) NULL

    ) ON [PRIMARY]

    truncate table DBFileLocations

    exec sp_MSforeachdb 'use [?]

    insert into DBFileLocations

    Select ''?'' as DBName, physical_name as ''Physical_Name'', substring(physical_name,1,1) as ''drive_letter''

    from [?].Sys.database_files'

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

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