Aboo Bolaky

{.NET, C#, Sitecore ...} Free your mind...

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

clock October 10, 2009 10:57 by author Aboo Bolaky

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

 

   1:  DECLARE @device_directory NVARCHAR(520)
   2:  SELECT @device_directory = SUBSTRING(filename, 1, CHARINDEX(N'master.mdf', LOWER(filename)) - 1)
   3:  FROM master.dbo.sysaltfiles WHERE dbid = 1 AND fileid = 1
   4:   
   5:  print @device_directory

Output

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

Currently rated 2.8 by 6 people

  • Currently 2.833333/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Comments

Add comment


(Will show your Gravatar )  

  Country flag

biuquote
  • Comment
  • Preview
Loading



A b o u t M e

Annoying

Brilliant

Open and

Objective

in every way..
Only Human >>
 
"First learn computer science and all the theory.

Next develop a programming style.

Then forget all that and just hack." Carrette (1990)