-1

I would like to know if there is any query that can be used to determine which drive, i.e. C:\ drive, SQL Server is located on.

Thanks in advance.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Kennedy Kan
  • 273
  • 1
  • 7
  • 20
  • Do you mean where the server files are installed, or where files for a particular database are? Or the default data directory? Please clarify your question. – Bridge Jun 16 '16 at 08:44

1 Answers1

1

Try this:

SELECT name, physical_name AS current_file_location FROM sys.master_files;

You can also use an undocumented system stored procedure to get the installation folder, e.g.:

DECLARE @Path VARCHAR(100);
SELECT @Path = NULL;
EXEC MASTER..xp_regread 'HKEY_LOCAL_MACHINE', 'SOFTWARE\Microsoft\Microsoft SQL Server\100\Tools\ClientSetup', 'SQLPath', @Path OUTPUT;
SELECT @Path;
Richard Hansell
  • 5,315
  • 1
  • 16
  • 35
  • To add to the completeness of your answer, if after the data directory, and OP is on SQL Server 2012 or newer, there's a cleaner way than using the registry: http://stackoverflow.com/a/16681314 – Bridge Jun 16 '16 at 08:52