要查看表索引,可以使用如下的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語句將返回更簡潔的索引信息,包括索引名稱、索引類型、是否唯一、是否主鍵等。