mssql sqlserver 查询指定表的下索引名称的语句分享


摘要:
使用系统存储过程查询出指定表下的索引的方法分享,如下所示:
实验环境:sql server 2008 R2


SELECT    a.name   as [索引名称]
,c.name as [表名]
,d.name as [索引字段名]
,d.colid as [索引字段位置]
FROM sysindexes a(nolock)
JOIN sysindexkeys b(nolock) ON a.id=b.id AND a.indid=b.indid
JOIN sysobjects c(nolock) ON b.id=c.id
JOIN syscolumns d(nolock) ON b.id=d.id AND b.colid=d.colid
WHERE a.indid NOT IN(0,255)
-- and c.xtype='U' and c.status>0
AND c.name='待查询表名'