查询以检查表上的索引 [英] Query to check index on a table

查看:141
本文介绍了查询以检查表上的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个查询来查看表中是否已经有任何索引。

I need a query to see if a table already has any indexes on it.

推荐答案

在SQL Server上,这将是列出指定表的所有索引:

On SQL Server, this will list all the indexes for a specified table:

select * from sys.indexes
where object_id = (select object_id from sys.objects where name = 'MYTABLE')

此查询将列出所有没有索引的表:

This query will list all tables without an index:

SELECT name
FROM sys.tables 
WHERE OBJECTPROPERTY(object_id,'IsIndexed') = 0

这是一个有趣的MSDN常见问题相关主题:

查询SQL Server系统目录常见问题解答

And this is an interesting MSDN FAQ on a related subject:
Querying the SQL Server System Catalog FAQ

这篇关于查询以检查表上的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆