SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

CanadaDBA
Aged Yak Warrior

Canada
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)

USA
7020 Posts

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




CODO ERGO SUM
Go to Top of Page

CanadaDBA
Aged Yak Warrior

Canada
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

pareshmotiwala
Constraint Violating Yak Guru

USA
322 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)
Begin
DROP TABLE #db_config
End
Go

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

CanadaDBA
Aged Yak Warrior

Canada
583 Posts

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

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

tkizer
Almighty SQL Goddess

USA
35932 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

RussStarksen
Starting Member

1 Posts

Posted - 11/14/2012 :  17:12:00  Show Profile  Reply with Quote
/* how about this query */
select @@servername,
a.name,
a.compatibility_level,
-- 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.name,a.compatibility_level
--,b.database_id

/* Russ */ Select * from Life; :-)
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.05 seconds. Powered By: Snitz Forums 2000