Solved

View mdf size of dbs in SQL 2005

Posted on 2010-11-15
6
340 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
[X]
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
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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Are triggers slow? 7 25
sql query help 15 55
SQL Server maintenance plan not deleting backup files as anticipated 4 19
T-SQL: I need to add an index on a field 5 27
There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
In this article I will describe the Copy Database Wizard 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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

726 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