Cor Blimey
Cor Blimey

Reputation: 83

How can I find mdf/ldf locations in T-SQL?

How can I find mdf/ldf locations in SQL2008 using T-SQL? Life is too short and error-prone to do it from the Properties screen.

Upvotes: 4

Views: 644

Answers (2)

M.Ali
M.Ali

Reputation: 69524

SELECT   DB_NAME(database_id) AS DatabaseName
        ,Name AS Logical_Name
        ,Physical_Name
        ,(size*8)/1024 SizeMB
FROM   sys.master_files
WHERE  DB_NAME(database_id) = 'Your_database_Name'
GO

or

Use Database_Name
GO

SELECT  name
       ,type_desc
       ,physical_name
       ,(size*8)/1024 SizeMB
FROM   sys.database_files
GO

Upvotes: 3

Raj
Raj

Reputation: 10853

Try this:

select filename FROM sysfiles

Upvotes: 1

Related Questions