I came across this wonderful t-sql script which displays the size of all the tables in a SQL Server Database. Thanks to Vidhya Sagar
SELECT 'Database Name: ', Db_name()
SET nocount ON
IF EXISTS(SELECT name
FROM tempdb..sysobjects
WHERE name = '##tmp')
DROP TABLE ##tmp
CREATE TABLE ##tmp
(
nam VARCHAR(50),
ROWS INT,
res VARCHAR(15),
data VARCHAR(15),
ind_sze VARCHAR(15),
unsed VARCHAR(15)
)
GO
DECLARE @tblname VARCHAR(50)
DECLARE tblname CURSOR FOR
SELECT name
FROM sysobjects
WHERE xtype = 'U'
OPEN tblname
FETCH NEXT FROM tblname INTO @tblname
WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO ##tmp
EXEC Sp_spaceused @tblname
FETCH NEXT FROM tblname INTO @tblname
END
CLOSE tblname
DEALLOCATE tblname
GO
SELECT nam table_name,
ROWS total_rows,
res total_table_size,
data data_size,
ind_sze index_size,
unsed unused_space
FROM ##tmp
DROP TABLE ##tmp
No comments:
Post a Comment