如果可能的话,我通常从原始表中取1000条记录,
把它们插到我自己的桌子上,
在下面的脚本中,我有一个示例可以使用。
好吧,这是不准确的,但可以给我一个起点。
--Find out the disk size of an index:
--USE [DB NAME HERE]
go
SELECT
OBJECT_NAME(I.OBJECT_ID) AS TableName,
I.name AS IndexName,
8 * SUM(AU.used_pages) AS 'Index size (KB)',
CAST(8 * SUM(AU.used_pages) / 1024.0 AS DECIMAL(18,2)) AS 'Index size (MB)'
FROM
sys.indexes I
JOIN sys.partitions P ON P.OBJECT_ID = I.OBJECT_ID AND P.index_id = I.index_id
JOIN sys.allocation_units AU ON AU.container_id = P.partition_id
--WHERE
-- OBJECT_NAME(I.OBJECT_ID) = '<TableName>'
GROUP BY
I.OBJECT_ID,
I.name
ORDER BY
TableName
--========================================================================================
--http://msdn.microsoft.com/en-us/library/fooec9de780-68fd-4551-b70b-2d3ab3709b3e.aspx
--I believe that keeping the GROUP BY
--is the best option in this case
--because of sys.allocation_units
--can have 4 types of data inside
--as below:
--type tinyint
--Type of allocation unit.
--0 = Dropped
--1 = In-row data (all data types, except LOB data types)
--2 = Large object (LOB) data (text, ntext, image, xml, large value types, and CLR user-defined types)
--3 = Row-overflow data
--marcelo miorelli 8-NOV-2013
--========================================================================================