Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / database / SQL-Server / SQL-Server-2014

Find the Size of Database mdf and ldf File in sql server

4.79/5 (10 votes)
30 Oct 2014CPOL 55.7K  
I show a SQL query which finds the size of database mdf and ldf file in SQL Server.

Introduction

I faced a situation where I needed to find the size of the log file. What was happening was that my database size was growing very large, so I wanted to see the size of my mdf and ldf file. I wrote a simple select statement to get it.

SQL
SELECT DB_NAME(database_id) AS DBName,Name AS Logical_Name, Physical_Name,(size*8)/1024 SizeMB
FROM sys.master_files
WHERE DB_NAME(database_id) = 'MyTestDB' --databasename

If we remove the WHERE condition, we will get the result for all the databases including system default database.

SQL
SELECT DB_NAME(database_id) AS DBName,Name AS Logical_Name,Physical_Name,(size*8)/1024 SizeMB
FROM sys.master_files

Points of Interest

We can do complex things in a simple manner.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)