|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Yesterday @ 5:24 AM
Points: 177,
Visits: 821
|
|
Hello All,
The report Disk Usage by Top Table is very usefull.
What is the source of the numbers in this report ? Or how can I get this report in a table ?
Now I use Excel as an intermediate and do some cutting an pasting.
Thanks for your time and attention, Ben Brugman
(Did a google search on : Disk Usage by top tables results in a table)
On [url=http://database.ittoolbox.com/groups/technical-functional/sql-server-l/tables-sizes-in-a-db-4071428][/url]
I found:
CREATE TABLE #TableSizes (name sysname, rows varchar(16), reserved varchar(16), data varchar(16), index_size varchar(16),unused varchar(16)) INSERT #TableSizes EXEC sp_MSforeachtable @command1="EXEC sp_spaceused '?'" SELECT TOP (100) * FROM #TableSizes ORDER BY DATA desc But here the numbers can not be sorted. (changing the declaration to bigint gives Msg 8114, Level 16, State 1, Procedure sp_spaceused, Line 178 Error converting data type varchar to bigint. )
Did a rebuild on that:
-- Create a tableSizes table which displays the same information as Disk Usage by Top Tables report. -- Ben Brugman -- 20121017 -- Part of the source comes from: -- http://database.ittoolbox.com/groups/technical-functional/sql-server-l/tables-sizes-in-a-db-4071428
CREATE TABLE ##TableSizes (name sysname, rows varchar(16), reserved varchar(16), data varchar(16), index_size varchar(16),unused varchar(16)) INSERT ##TableSizes EXEC sp_MSforeachtable @command1="EXEC sp_spaceused '?'"
update ##TableSizes set Reserved = replace(reserved,'kb',''), index_size = replace(reserved,'kb',''), data = replace(reserved,'kb',''), unused = replace(reserved,'kb','')
CREATE TABLE ##TableSizes2 (name sysname, rows bigint, reserved bigint, data bigint, index_size bigint,unused bigint) insert into ##TableSizes2 select * from ##TableSizes
SELECT TOP (1000) * FROM ##TableSizes2 ORDER BY reserved desc drop table ##TableSizes drop table ##TableSizes2
This is a bit cumbersome, I think that there is a more direct solution/call/script ?
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Thursday, June 13, 2013 7:03 AM
Points: 2,562,
Visits: 3,453
|
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Today @ 4:59 PM
Points: 386,
Visits: 1,425
|
|
Bhuvnesh (10/17/2012) use varchar(16) instead of bigint The OP cannot sort the result set using varchar, hence the bigint.
The SQL Guy @ blogspot
About Me
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 4:08 PM
Points: 38,099,
Visits: 30,392
|
|
Far easier way, just query sys.dm_db_partition_stats.
Gail Shaw Microsoft Certified Master: SQL Server 2008, MVP SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter We stand on the bridge and no one may pass
|
|
|
|