SQL Server查询某个表的索引信息
查看表的索引,通过一些工具我们可以很简单的获取到对应的索引信息,但是怎么通过SQL获取呢?这里介绍两种方法1.通过存储过程sp_helpindex获取内置存储过程sp_helpindex可获取表对应的索引。如下(UpgradeInfo是表名):EXEC sp_helpindex 'UpgradeInfo';index_nameindex_descriptionindex_keysPK_Upgrad
·
查看表的索引,通过一些工具我们可以很简单的获取到对应的索引信息,但是怎么通过SQL获取呢?这里介绍两种方法
1.通过存储过程sp_helpindex获取
内置存储过程sp_helpindex可获取表对应的索引。
如下(UpgradeInfo是表名):
EXEC sp_helpindex 'UpgradeInfo';
index_name index_description index_keys
PK_UpgradeInfo clustered, unique, primary key located on PRIMARY Item
2.通过系统视图sys.indexes获取
通过 sys.indexes 视图 可获取表对应的索引。
如下(UpgradeInfo是表名):
SELECT * FROM sys.indexes where object_id = (select object_id from sys.all_objects where name = 'UpgradeInfo');
object_id name index_id type type_desc is_unique data_space_id ignore_dup_key is_primary_key is_unique_constraint fill_factor is_padded is_disabled is_hypothetical allow_row_locks allow_page_locks has_filter filter_definition compression_delay
741577680 PK_UpgradeInfo 1 1 CLUSTERED 1 1 0 1 0 0 0 0 0 1 1 0
获取object_id 也可以通过select OBJECT_ID('UpgradeInfo');
所以也可以这样:
SELECT * FROM sys.indexes where object_id = (select OBJECT_ID('UpgradeInfo'));
更多推荐
已为社区贡献20条内容
所有评论(0)