gpt4 book ai didi

SQL Server - 查找基于特定数据类型构建的所有聚集索引的脚本

转载 作者:行者123 更新时间:2023-12-04 04:30:11 25 4
gpt4 key购买 nike

我试图找到所有建立在数据类型 uniqueIdentifier 列上的聚集索引。显然,这对于聚集索引来说是一个糟糕的选择,我正试图找到所有这些并删除它们。到目前为止,我编写的脚本为每个具有 uniqueIdentifier 的表返回所有聚集索引。请帮忙。这是脚本:

select distinct object_name(i.object_id) AS tablename, i.name AS indexname, i.type_desc     as type 
from sys.indexes i
join sys.index_columns ic on ic.object_id = i.object_id and ic.index_id = i.index_id
join sys.columns c on c.column_id = ic.index_column_id
join sys.types t on t.system_type_id = c.system_type_id
join sys.objects o on o.object_id = i.object_id
where t.name = 'uniqueidentifier'
and i.type_desc = 'clustered'
and object_name(i.object_id) not like 'sys%'

最佳答案

select o.name objectname, i.name indexname, c.name as columnname
from sys.objects o
join sys.indexes i on i.object_id = o.object_id
join sys.index_columns ic on ic.index_id = i.index_id and ic.object_id = i.object_id
join sys.columns c on c.object_id = o.object_id and c.column_id = ic.column_id
join sys.types t on c.system_type_id = t.system_type_id
where o.is_ms_shipped = 0
and i.type_desc = 'CLUSTERED'
and t.name = 'uniqueidentifier'
order by o.name, i.name

关于SQL Server - 查找基于特定数据类型构建的所有聚集索引的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13390721/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com