We walk in the dark places no others will enterWe stand on the bridge and no one may pass
use MyDBgoDECLARE @names TABLE( id INT IDENTITY(1,1), name NVARCHAR(100) NULL)DECLARE @ROWCOUNT INTDECLARE @i INT = 1DECLARE @str nvarchar(100)INSERT INTO @names(name) SELECT name FROM sys.TablesSET @ROWCOUNT = @@ROWCOUNTDECLARE @space TABLE( name NVARCHAR(100) NULL, rows CHAR(11), reserved NVARCHAR (15), data NVARCHAR (18), indexes NVARCHAR (18), unused NVARCHAR (18))WHILE @i <= @ROWCOUNTBEGIN SELECT @str = name FROM @names WHERE id = @i INSERT INTO @space EXEC sp_spaceused @str SET @i += 1ENDSELECT * FROM @spaceORDER BY CONVERT( BIGINT, rows ) DESC;
SELECT DB_NAME() AS DatabaseName , object_name(i.object_id) AS TableName , ISNULL(i.name, 'HEAP') AS IndexName , i.index_id AS IndexID , i.type_desc AS IndexType , p.partition_number AS PartitionNo , p.[rows] AS NumRows , au.type_desc AS InType , au.total_pages AS NumPages , au.total_pages * 8 AS TotKBs , au.used_pages * 8 AS UsedKBs , au.data_pages * 8 AS DataKBsFROM sys.indexes i INNER JOIN sys.partitions p ON i.object_id = p.object_id AND i.index_id = p.index_idINNER JOIN sys.allocation_units au ONCASE WHEN au.[type] in (1,3) THEN p.hobt_idWHEN au.type = 2 THEN p.partition_idend = au.container_idINNER JOIN sys.objects o ON i.object_id = o.object_idWHERE o.is_ms_shipped <> 1ORDER BY TableName, i.index_id