Getting the size of database tables and sorting on size



Getting the size of database tables and sorting on size.

-- create the temporary table
CREATE TABLE #tableSize
([tablename] NVARCHAR(128),
 [noofrows] CHAR(18),
 sizereserved VARCHAR(20),
 sizedata VARCHAR(20),
 index_size VARCHAR(20),
 unused VARCHAR(20)
 )

--insert the data
INSERT #tableSize EXEC sp_msForEachTable 'EXEC sp_spaceused ''?'''

--select & drop the table
select tablename,  CAST(noofrows AS INT), CAST(LEFT(sizedata, len(sizedata)-3) AS INT)/1024 as Size_MB from #tableSize order by 2 desc

drop table #tableSize

Comments

Popular posts from this blog

Restoring Master, Model and MSDB from Netbackup

Oracle Job Operations