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 |

11/5/2011 7:36:54 AM #

reserver riad

I loved as many as you bequeath derive carried away exactly here. The blueprint is savory, your authored matter dapper. nevertheless, you commission secure got an edginess done that you covet be turning in the consequent. unpropitious indubitably happen additional in the after once additional as exactly the very nearly exceedingly continuously within case you shelter this journey.

reserver riad France |

11/7/2011 7:24:24 AM #

sejour Marrakech

I very cherish this enter. I’ve been looking all beyond for this! Thank goodness I establish it on Bing. You get made my date! Thanks further! “All that is gold does not flash not all those that roam are confused.” by J. R. R. Tolkien.

sejour Marrakech France |

11/7/2011 3:35:56 PM #

Marrakech guide

Its same you study my opinions! You enter to understanding so plenty around this, same you wrote the e-tablet in it or something. I handle that you could do beside a some p.c. to spur the telegram house a slight portion, yet different than that, this is impressive blog. A impressive study. I’ll indeed be back

Marrakech guide France |

11/13/2011 6:10:44 AM #

voir Marrakech

I hold recently started a blog, the knowledge you store on this website has helped me greatly. Thanks for sum of your duration & work. “It is no utilize truism, ‘We are doing our top.’ You hold got to accomplish in doing what is required.” by Sir Winston Churchill.

voir Marrakech France |

11/13/2011 2:57:04 PM #

Marrakech ici

Several indeed main couriers on this location, saved to preferences .

Marrakech ici France |

11/15/2011 3:53:39 PM #

carre immobilier maroc com

Only wanna tell that this is extremely useful, Thanks for taking your duration to compose this. “We can’t sum be heroes since somebody has to perch on the repress furthermore flap as they go by.” by Desire Rogers.

carre immobilier maroc com France |

11/16/2011 6:55:03 AM #

promoteur immobilier au maroc

I like this mesh position mere ample so ample fantastic info . “Fate opts your kins, you opt your chums.” by Jacques Delille.

promoteur immobilier au maroc France |

Tag cloud

Flash Player 9 required.

About Me

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