I need to write a script to check if a column is indexed in the table it belongs to, if not then add an index for it. MySQL doesn’t seem to have ADD INDEX IF NOT EXISTS.
What’s the best way to do this in MySQL?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
See http://dev.mysql.com/doc/refman/5.1/en/create-index.html
There is a stored procedure that does this (remember, not my code, just
the first hit on google with
mysql add index if not existsas search string).There is an alternative version right underneath it in the same page.