我们如何检查该表是否有索引?

时间:2022-05-10 15:06:22

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

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

Regards, kumar

此致,库马尔

3 个解决方案

#1


13  

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.

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

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

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

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

#2


0  

ordering by column name is wrong, you need to order by the position in the index, so order by clause should be tabname, indname and sys.index_columns.index_column_id...

按列名排序是错误的,你需要按索引中的位置排序,所以order by子句应该是tabname,indname和sys.index_columns.index_column_id ...

#3


-1  

Try

尝试

select object_name(object_id),* from sys.indexes 
where object_name(object_id) = 'your table name'

#1


13  

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.

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

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

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

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

#2


0  

ordering by column name is wrong, you need to order by the position in the index, so order by clause should be tabname, indname and sys.index_columns.index_column_id...

按列名排序是错误的,你需要按索引中的位置排序,所以order by子句应该是tabname,indname和sys.index_columns.index_column_id ...

#3


-1  

Try

尝试

select object_name(object_id),* from sys.indexes 
where object_name(object_id) = 'your table name'