Is there a way to find the physical path of SQL Server file (.mdf)? I have VS2010 where I browse the SQL Server database in Server Explorer window. I do not have sql Server Management studio.
Thanks in advance
Is there a way to find the physical path of SQL Server file (.mdf)? I have VS2010 where I browse the SQL Server database in Server Explorer window. I do not have sql Server Management studio.
Thanks in advance
This gives the database where name = 'master'. Just change this to the database you're looking for.
SELECT name, physical_name AS current_file_location
FROM sys.master_files
WHERE name = 'master'
You can also try:
SELECT filename FROM sys.sysfiles
This gives the default locations
DECLARE @defaultDataLocation nvarchar(4000)
DECLARE @defaultLogLocation nvarchar(4000)
EXEC master.dbo.xp_instance_regread
N'HKEY_LOCAL_MACHINE',
N'Software\Microsoft\MSSQLServer\MSSQLServer',
N'DefaultData',
@defaultDataLocation OUTPUT
EXEC master.dbo.xp_instance_regread
N'HKEY_LOCAL_MACHINE',
N'Software\Microsoft\MSSQLServer\MSSQLServer',
N'DefaultLog',
@defaultLogLocation OUTPUT
SELECT @defaultDataLocation, @defaultLogLocation