mysql - Add index to table if it does not exists -
i want add index table using alter
syntax , want check if index exists in table, , if not exists, add index.
alter table tablename add index ix_table_xyz (column1);
is there way this?
try this:
set @x := (select count(*) information_schema.statistics table_name = 'table' , index_name = 'ix_table_xyz' , table_schema = database()); set @sql := if( @x > 0, 'select ''index exists.''', 'alter table tablename add index ix_table_xyz (column1);'); prepare stmt @sql; execute stmt;
Comments
Post a Comment