Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 List databases with their size
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Aged Yak Warrior

583 Posts

Posted - 02/12/2007 :  14:27:51  Show Profile  Reply with Quote
I want to list my databases, and physical related files, and their size but the following commands do not provide the size. Any idea?

SELECT * FROM sysdatabases
SELECT * FROM sys.sysfiles

I know it's silly question

Canada DBA

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 02/12/2007 :  14:36:49  Show Profile  Reply with Quote
Size is the third column in sys.sysfiles

Go to Top of Page

Aged Yak Warrior

583 Posts

Posted - 02/12/2007 :  14:52:22  Show Profile  Reply with Quote
That size is in 8KB and is only for the DB being in USE. For example if the size has a value of 512, it means the file size is 4096 kb. Then I have to have a cursor to navigate all my databases.

Isn't there a table or view containing the databases and their files and sizes?

Canada DBA
Go to Top of Page

Constraint Violating Yak Guru

323 Posts

Posted - 02/12/2007 :  14:53:49  Show Profile  Visit pareshmotiwala's Homepage  Click to see pareshmotiwala's MSN Messenger address  Send pareshmotiwala a Yahoo! Message  Reply with Quote
if exists (select * from dbo.sysobjects where name = '#db_config' and OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE #db_config

set nocount off
create table #db_config
name_col varchar(30),
db_size varchar(20),
owner varchar(50),
dbid int,
created varchar(20),
status varchar(255),
compatibility_level varchar(20)

insert #db_config
exec sp_helpdb

Select name_col,db_size from #db_config

set nocount on

You may have to tweak this a bit because the sp_helpdb returns results with different datatypes and length in different versions.

Edited by - pareshmotiwala on 02/12/2007 14:54:57
Go to Top of Page

Aged Yak Warrior

583 Posts

Posted - 02/12/2007 :  14:58:22  Show Profile  Reply with Quote

SELECT Name [Database], Physical_Name [Physical file], size*8 [Size_KB] FROM sys.master_files

Thanks for all posts!

Canada DBA
Go to Top of Page

Almighty SQL Goddess

38200 Posts

Posted - 02/12/2007 :  15:01:11  Show Profile  Visit tkizer's Homepage  Reply with Quote
Just run sp_databases.

Tara Kizer
Go to Top of Page

Starting Member

1 Posts

Posted - 11/14/2012 :  17:12:00  Show Profile  Reply with Quote
/* how about this query */
select @@servername,,
-- b.database_id [database_id],
SUM(((size*8)/1024)) [Size_MB]
FROM sys.databases a,sys.master_files b
where a.database_id=b.database_id
group by,a.compatibility_level

/* Russ */ Select * from Life; :-)
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000