我们如何检查表是否有索引? [英] How can we check that table have index or not?

查看:66
本文介绍了我们如何检查表是否有索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何检查表是否有索引?如果有如何为表的特定列找到该索引?

How can we check that table have index or not ? if have how to find that index for a particular column for a table?

问候,库马尔

推荐答案

在 SQL Server Management Studio 中,您可以在树中向下导航到您感兴趣的表并打开索引节点.双击该节点中的任何索引将打开属性对话框,其中将显示索引中包含哪些列.

In SQL Server Management Studio you can navigate down the tree to the table you're interested in and open the indexes node. Double clicking any index in that node will then open the properties dialog which will show which columns are included in the index.

如果您想使用 T-SQL,这可能会有所帮助:

If you would like to use T-SQL, this might help:

SELECT
    sys.tables.name,
    sys.indexes.name,
    sys.columns.name
FROM sys.indexes
    INNER JOIN sys.tables ON sys.tables.object_id = sys.indexes.object_id
    INNER JOIN sys.index_columns ON sys.index_columns.index_id = sys.indexes.index_id
        AND sys.index_columns.object_id = sys.tables.object_id
    INNER JOIN sys.columns ON sys.columns.column_id = sys.index_columns.column_id
        AND sys.columns.object_id = sys.tables.object_id
WHERE sys.tables.name = 'TABLE NAME HERE'
ORDER BY
    sys.tables.name,
    sys.indexes.name,
    sys.columns.name

这篇关于我们如何检查表是否有索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆