HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMinor

How to check for existence of an INDEX on a column independent of used SQL database

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
existencecolumnindependentusedsqldatabaseforhowindexcheck

Problem

Is there are unified way of how to check for the existance of an INDEX for a given column irregardless of the actual SQL database system used?

For MySQL one could for instance check for the existance using SHOW CREATE TABLE mytable. In the result there would be something like this if column mycolumn has an index: KEY 'Index_1' ('mycolumn').

Is this indicator KEY unified among all SQL database systems?

Are there better ways to check for an index?

Solution

I'm afraid not.

The ANSI SQL standard defines some data dictionary views in a schema ("INFORMATION_SCHEMA") that can be used to look for specific types of objects (tables, views, table columns), but it doesn't include anything regarding indexes.

Most RDBMSes have their own internal data dictionary views that expose this information (sysindexes in SQL Server & Sybase, DBA_INDEXES in Oracle, for example).

Context

StackExchange Database Administrators Q#63825, answer score: 7

Revisions (0)

No revisions yet.