Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

View mdf size of dbs in SQL 2005

Posted on 2010-11-15
6
339 Views
Last Modified: 2012-05-10
Hello there,
I have a instance in SQL 2005 Ent with 32 DB;s and I need to know the sql script/command that I can run to display size of mdf's of each of these DB's.
Please advise.
Thanks

0
Comment
Question by:goprasad
6 Comments
 
LVL 7

Expert Comment

by:mkobrin
ID: 34142814
run the sp_databases stored procedure on the master data base. It will supply you with the info you need
0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 34143267
For just the .mdf files (not including log files or .ndf secondary files)

exec sp_msforeachdb 'use ?; select db_name(), size*8 as ''in KB'', filename from sysfiles where filename like ''%.mdf'''

For all data files (non log)

exec sp_msforeachdb 'use ?; select db_name(), size*8 as ''in KB'', filename from sysfiles where groupid>0'
0
 
LVL 6

Expert Comment

by:subhashpunia
ID: 34143419
a simple command is:

sp_msforeachdb 'sp_helpdb [?]'
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 6

Accepted Solution

by:
subhashpunia earned 500 total points
ID: 34143598
You can get the result in temp table and see in better way as below:

create table #DataFileSize (DBName VARCHAR(1000), Size_KB int, FilePath varchar(4000))
insert into #DataFileSize
exec sp_msforeachdb 'use [?]; select db_name(), size*8 as ''in KB'', filename from sysfiles where filename like ''%.mdf'''
select DBName, FilePath, Size_KB/1024 As FileZise_MB from #DataFileSize
drop table #DataFileSize
0
 
LVL 2

Expert Comment

by:AvalonSA
ID: 34144767
I believe that the most easy way is:
select db.name, mf.physical_name, mf.size*8 as "KB"
from sys.master_files mf join sys.databases db
on mf.database_id = db.database_id
where physical_name like '%.mdf'

Data files are not only mdf, each additional is called .ndf or you can specify whatever you want so to be sure you can execute this (Retrieve the datafiles size of all DB data files):

select db.name, mf.physical_name, mf.size*8 as "KB"
from sys.master_files mf join sys.databases db
on mf.database_id = db.database_id
where mf.type_desc = 'ROWS'
0
 

Author Closing Comment

by:goprasad
ID: 34179267
Solved my problem, great sql command and subsequent output.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question