August 13, 2009

Display List of All Databases with their Sizes in SQL Server 2005/2008

Here’s a query that lists the properties of a database using the sys.master_files and sys.databases, both System Views for retrieving Database information.

SELECT sysDa.Name,sysDa.create_date,sysDa.recovery_model_desc, temp.DBSize8KBPage
SELECT sysMas.database_ID, sysMas.size, SUM(size) as DBSize8KBPage
FROM sys.master_Files sysMas
GROUP BY sysMas.DataBase_ID, sysMas.size
Sys.Databases sysDa
on temp.Database_ID = sysDa.DataBase_ID



About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

No comments: