Friday, April 3, 2009

SQL Server 2005 - Get Size of Database and Individual Tables

-- Get size of Database
EXEC DATABASENAME.dbo.sp_spaceused

-- Get size of a Table in database
EXEC DATABASENAME.dbo.sp_spaceused 'TABLENAME'

-- Get size of All tables in a database
EXEC DATABASENAME.dbo.sp_spaceused '?'

-- Sql Query
USE DATABASENAME
GO
DECLARE @database_size DECIMAL(15,2)
SELECT @database_size = SUM(((convert (dec (15,2),[size]) * 8192 / 1048576)))
FROM dbo.sysfiles
PRINT @database_size

No comments:

Post a Comment