SET NOCOUNT ON
CREATE TABLE #space
(
name VARCHAR(64),
rows INT,
reserved VARCHAR(64),
DATA VARCHAR(64),
index_size VARCHAR(64),
unused VARCHAR(64)
)
DECLARE c_cursor CURSOR for SELECT NAME FROM sysobjects s WHERE TYPE = 'U'
DECLARE @tab_name VARCHAR(64)
OPEN c_cursor
FETCH c_cursor INTO @tab_name
WHILE @@FETCH_STATUS = 0
BEGIN
insert into #space EXEC sp_spaceused @tab_name
FETCH c_cursor INTO @tab_name
END
CLOSE c_cursor
DEALLOCATE c_cursor
UPDATE #space SET reserved = replace(reserved, 'KB', '')
SELECT name, rows, convert(varchar, round(convert(int, reserved)*1.0/1024,2)) + 'M' FROM #space ORDER BY convert(int, reserved) desc
DROP table #space
GO