我试图找到构建在数据类型uniqueIdentifier的列上的所有聚簇索引。显然这是一个聚集索引的可怕选择,我试图找到所有这些并将其删除。我迄今为止编写的脚本为每个具有uniqueIdentifier的表返回所有聚簇索引。请帮忙。下面是该脚本:SQL Server的脚本来查找建立在特定数据类型上的所有聚簇索引
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%'
它看起来像你的丢失位为ON子句SYS.COLUMNS,其中应包括OBJECT_ID – RichardTheKiwi
这是一个可怕的选择** **如果值被随机分配(如通过'newid()')。如果分配顺序值,它不一定是一个可怕的选择。 –