【发布时间】:2017-06-25 21:20:14
【问题描述】:
In article about sys.indexes有一句话表示这个观点
包含表格对象(例如表格)的每个索引或堆的一行, 视图或表值函数。
我有兴趣找到这样一个索引的大小。
所以我用索引创建了函数:
create function fIndexSize()
returns @res table
(
object_id int not null
, name varchar(128) not null
, primary key (object_id)
)
as
begin
insert into @res
select object_id, name
from sys.objects
where object_id > 255
return
end
这里我们可以看到新索引的名称:
sys.indexes中也有记录:
通常我使用这个查询获得索引的大小:
select
o.schema_id
, o.object_id
, o.name
, o.type_desc
, sum (a.total_pages) * 8.00 / 1024 / 1024 as TotalSpaceGB
from sys.objects o
inner join sys.indexes i on o.object_id = i.object_id
inner join sys.partitions p on i.object_id = p.object_id and i.index_id = p.index_id
inner join sys.allocation_units a on p.partition_id = a.container_id
where (o.name = 'fIndexSize' or i.name like 'PK__fIndexSi%')
group by o.schema_id, o.object_id, o.name, o.type_desc
但这一次没有返回任何东西。
谁能给我建议如何找到这样一个索引的大小?
【问题讨论】:
标签: sql sql-server