我正在尝试查找在数据类型为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%'发布于 2012-11-15 10:48:43
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.namehttps://stackoverflow.com/questions/13390721
复制相似问题