SQL Server - get all databases with MDF and LDF File Location

后端 未结 3 1731
长发绾君心
长发绾君心 2020-12-24 13:38

I need a T-SQL query for a list of all databases in SQL Server 2008 showing

  • the name of the database and
  • the location of the .mdf and
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-24 14:35

    select 
        d.name as 'database',
        mdf.physical_name as 'mdf_file',
        ldf.physical_name as 'log_file'
    from sys.databases d
    inner join sys.master_files mdf on 
        d.database_id = mdf.database_id and mdf.[type] = 0
    inner join sys.master_files ldf on 
        d.database_id = ldf.database_id and ldf.[type] = 1
    

提交回复
热议问题