Monday, 31 July 2017

Get the Size of all Tables in a database in sql server

Using below sql script we will get the size of the tables in a database.
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

Drop table #TableSize

Running this sql script.
  
I have run it on Test database.
Now I am running on other database see the result.

 

No comments:

Post a Comment

If you have any doubt, please let me know.

Popular Posts