I need a query to see if a table already has any indexes on it.
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.
1 Answer. Show activity on this post. Write "explain " in front of your query. The result will tell you which indexes might be used.
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>.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With