Retrieving the DATA folder installation path from MS SQL Server using T/SQL

by aboo bolaky 10. October 2009 19:57

This would be useful for creating databases using SQL scripts. The SQL query below returns the installation path of the DATA folder for the installed SQL Server.

SQL Script

 

DECLARE @device_directory NVARCHAR(520)

SELECT @device_directory = 
	SUBSTRING(filename, 1, CHARINDEX(N'master.mdf', LOWER(filename)) - 1)
FROM master.dbo.sysaltfiles 
WHERE dbid = 1 AND fileid = 1

print @device_directory

Output

C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\

Tags:

The AByss | Tips & Tricks

Comments

5/15/2010 4:41:04 PM #

Cheap Domain Names

Top post. I look forward to reading more. Cheers

Cheap Domain Names United Kingdom |

Tag cloud

Flash Player 9 required.

About Me

I wish I could write something here..
//TODO: ElaborateMe