SQL server查看各表的索引(sql语句大全)
时间:2023-12-28 15:26:31 来源:未知 作者:阿里技术 阅读:
1、要查看 SQL Server 数据库中的索引,可以使用如下 SQL 语句:
SELECT
TableName = t.name,
IndexName = ind.name,
ind.type_desc,
ind.is_unique,
ind.is_primary_key,
ColumnNames =
stuff(
(
select ', ' + col.name +
case when ic.is_descending_key = 1 then ' desc' else '' end
from sys.index_columns ic
inner join sys.columns col on ic.object_id = col.object_id and ic.column_id = col.column_id
where
ic.object_id = ind.object_id
and ic.index_id = ind.index_id
order by
ic.index_column_id
for xml path ('')
),1,2,''
)
FROM
sys.indexes ind
INNER JOIN sys.tables t ON ind.object_id = t.object_id
INNER JOIN sys.schemas s ON t.schema_id = s.schema_id
WHERE
ind.name IS NOT NULL
ORDER BY
发表评论
共有0条评论
扫码关注公众号
获取全套技术教程