Query to check index on a table
Solution 1:
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
Solution 2:
If you're using MySQL you can run SHOW KEYS FROM table
or SHOW INDEXES FROM table
Solution 3:
If you just need the indexed columns EXEC sp_helpindex 'TABLE_NAME'
Solution 4:
Simply you can find index name and column names of a particular table using below command
SP_HELPINDEX 'tablename'
It work's for me
Solution 5:
Most modern RDBMSs support the INFORMATION_SCHEMA
schema. If yours supports that, then you want either INFORMATION_SCHEMA.TABLE_CONSTRAINTS
or INFORMATION_SCHEMA.KEY_COLUMN_USAGE
, or maybe both.
To see if yours supports it is as simple as running
select count(*) from INFORMATION_SCHEMA.TABLE_CONSTRAINTS
EDIT: SQL Server does have INFORMATION_SCHEMA
, and it's easier to use than their vendor-specific tables, so just go with it.