Solved

View mdf size of dbs in SQL 2005

Posted on 2010-11-15
6
336 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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

706 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now