Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

View mdf size of dbs in SQL 2005

Posted on 2010-11-15
6
Medium Priority
?
346 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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 6

Accepted Solution

by:
subhashpunia earned 2000 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

618 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