INFORMATICS

The Best

Przełącznik języka

This Site

CMS

Hardware

Databases

Emulators

Powershell

Storage Array

Antivirus program

Licznik

2.png3.png6.png7.png8.png9.png9.png
Today193
Yesterday560
This week5340
This month18069
Total2367899

Visitor Info

  • IP: 34.204.174.110
  • Browser: Unknown
  • Browser Version:
  • Operating System: Unknown

Who Is Online

4
Online

Domingo, 29 Mayo 2022 11:17

How to View SQL Server Database Size and File Locations

Inicio desactivadoInicio desactivadoInicio desactivadoInicio desactivadoInicio desactivado
 

How to View SQL Server Database Size and File Locations

 

SELECT
--database ID
mdf.database_id,
--database name
mdf.name,
--database file location
mdf.physical_name as data_file,
ldf.physical_name as log_file,
db_size_MB = CAST((mdf.size * 8.0)/1024 AS DECIMAL(8,2)),
log_size = CAST((ldf.size * 8.0 / 1024) AS DECIMAL(8,2))

FROM (SELECT * FROM sys.master_files WHERE type_desc = 'ROWS' ) mdf

JOIN (SELECT * FROM sys.master_files WHERE type_desc = 'LOG' ) ldf

ON mdf.database_id = ldf.database_id
--sort  DESC or ASC
order by db_size_MB DESC

Search