Click here to Skip to main content
15,885,546 members
Articles / Database Development / SQL Server / SQL Server 2014
Tip/Trick

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

Rate me:
Please Sign up or sign in to vote.
4.79/5 (10 votes)
30 Oct 2014CPOL 53.1K   5   5
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)



Comments and Discussions

 
QuestionQuick Tip - Nice! Pin
Ken of Kendoria8-Nov-14 5:57
professionalKen of Kendoria8-Nov-14 5:57 
GeneralMy vote of 3 Pin
Tomas Takac3-Nov-14 23:48
Tomas Takac3-Nov-14 23:48 
QuestionRights Pin
Master6831-Oct-14 4:52
Master6831-Oct-14 4:52 
GeneralMy vote of 5 Pin
Humayun Kabir Mamun30-Oct-14 19:40
Humayun Kabir Mamun30-Oct-14 19:40 
GeneralRe: My vote of 5 Pin
Arvind Singh Baghel31-Oct-14 2:08
Arvind Singh Baghel31-Oct-14 2:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.