Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query to check index on a table

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

like image 847
sine Avatar asked Nov 25 '09 23:11

sine


People also ask

How can I see all indexes on a table in SQL Server?

You can use the sp_helpindex to view all the indexes of one table. And for all the indexes, you can traverse sys. objects to get all the indexes for each table.

How do I check if a query is indexed?

1 Answer. Show activity on this post. Write "explain " in front of your query. The result will tell you which indexes might be used.

How do I find the index of a column in a table?

To show indexes for a particular table in Oracle use the following command: select index_name from dba_indexes where table_name='tablename'; When showing indexes, make sure that you are giving the right <tablename>.


1 Answers

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 

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

like image 68
gkrogers Avatar answered Sep 23 '22 06:09

gkrogers