如果一个表有为其列'col'创建的索引,则更改该列会给出类似“索引'index1'依赖于列'col'。”
给定表名和列名,如何编写SQL查询以列出该列的依赖索引?
数据库是MSSQL2008R2
谢谢
答案 0 :(得分:2)
您可以简单地查询元数据:
SELECT IndexName = i.Name
FROM [sys].[index_columns] ic
INNER JOIN [sys].[columns] c
ON ic.[object_id] = c.[object_id]
AND ic.[column_id] = c.[column_id]
INNER JOIN [sys].[indexes] i
ON i.[object_id] = ic.[object_id]
AND i.[index_id] = ic.[index_id]
WHERE ic.[object_id] = OBJECT_ID('dbo.TableName')
AND c.Name = 'ColumnName';