-1

如果一个表有为其列 'col' 创建的索引,则更改该列将给出类似“索引 'index1' 依赖于列 'col'”。

给定一个表名和一个列名,如何编写 SQL 查询来列出该列的依赖索引?

数据库是 MSSQL2008R2

谢谢

4

1 回答 1

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';
于 2013-09-06T11:42:09.240 回答