How to find if a specific INDEX NAME / KEYNAME exists in a Table
How to find if a specific INDEX NAME / KEYNAME exists in a Table

How to find if a specific INDEX NAME / KEYNAME exists in a Table

Advertisment
How to know if a KEYNAME already exists?

 

The following query will return empty if the keyname is not found. Else it will show the keyaname.

Simply replace 'INDEX_NAME  / KEY_NAME' for your Key Name, 'TABLE_NAME' for your Table Name and 'DBNAME' for your Database name, which is optional as you can read in the comments.

 

SELECT DISTINCT
INDEX_NAME FROM INFORMATION_SCHEMA.STATISTICS
WHERE INDEX_NAME = 'INDEX_NAME  / KEY_NAME'
and TABLE_NAME='TABLE_NAME'
and  TABLE_SCHEMA = 'DBNAME'  //this last one is optional, unless you are dealing with multiple database with the same table names,

Comments

Get a Quote

Get a Quote