sqlserver怎么查看表索引

avatar
作者
猴君
阅读量:0

要查看表索引,可以使用如下的SQL语句:

-- 查看表的所有索引 EXEC sp_helpindex 'table_name';  -- 查看表的索引信息和统计信息 SELECT      i.name AS index_name,     i.type_desc AS index_type,     i.is_unique,     i.is_primary_key,     c.name AS column_name,     ic.index_column_id AS column_order,     ic.key_ordinal AS key_order,     ic.is_descending_key FROM     sys.indexes AS i     JOIN sys.index_columns AS ic ON i.object_id = ic.object_id AND i.index_id = ic.index_id     JOIN sys.columns AS c ON ic.object_id = c.object_id AND ic.column_id = c.column_id WHERE     OBJECT_NAME(i.object_id) = 'table_name' ORDER BY     ic.index_column_id; 

其中,将table_name替换为你要查看的表的名称。第一条SQL语句会显示表的所有索引的详细信息,包括索引名称、列名称、索引类型等。第二条SQL语句将返回更简洁的索引信息,包括索引名称、索引类型、是否唯一、是否主键等。

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!