I am using MySQL v5.1.
I would like to create index on a table by executing the following SQL statement:
CREATE INDEX index_name
ON table_name (column_name)
But, I wan to firstly check if the index on that column has already been created or not, if not, create it (otherwise do not create). What is the SQL syntax for this?
Mysql doesn’t have
IF NOT EXISTSforCREATE INDEX. You can work it out by queryinginformation_schema.statisticstable. Take a look here, there is an example of stored procedure that does what you are looking for (search for “CREATE INDEX IF NOT EXISTS” on the page)