Listing information about all database files in SQL Server

后端 未结 13 2112
遥遥无期
遥遥无期 2021-02-01 00:08

Is it possible to list information about the files (MDF/LDF) of all databases on an SQL Server?

I\'d like to get a list showing which database is using what files on th

13条回答
  •  再見小時候
    2021-02-01 00:48

    If you want get location of Database you can check Get All DBs Location.
    you can use sys.master_files for get location of db and sys.databse to get db name

    SELECT
        db.name AS DBName,
        type_desc AS FileType,
        Physical_Name AS Location
    FROM
        sys.master_files mf
    INNER JOIN 
        sys.databases db ON db.database_id = mf.database_id
    

提交回复
热议问题