T-SQL: Table Sizes in SQL Server

T-SQL: Table Sizes in SQL Server

--one table
sp_spaceused 'TABLE_NAME'

--all tables
EXEC sp_MSforeachtable 'EXEC sp_spaceused ''?'''

--OR

IF OBJECT_ID('tempdb..#TableSize') IS NOT NULL
DROP TABLE #TableSize
CREATE TABLE #TableSize
(
SEQ INT IDENTITY(1,1) ,
name NVARCHAR(200),
rows BIGINT,
reserved VARCHAR(100),
data VARCHAR(100),
index_size VARCHAR(100),
unused VARCHAR(100)
)

INSERT #TableSize
EXEC sp_MSforeachtable 'EXEC sp_spaceused ''?'''
SELECT* FROM #TableSize

 

Leave a Comment
  • Please add 6 and 8 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
  • Naomi  N edited Revision 4. Comment: Title change

Page 1 of 1 (1 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
  • Naomi  N edited Revision 4. Comment: Title change

Page 1 of 1 (1 items)