php - How can I employ "if exists" for creating or dropping an index in MySQL? -
i wondering if there's way check if index exists before creating or destroying on mysql. appears there feature request few years back, can't find documentation solution. needs done in php app using mdb2.
here 4 liner:
set @exist := (select count(*) information_schema.statistics table_name = 'table' , index_name = 'index' , table_schema = database()); set @sqlstmt := if( @exist > 0, 'select ''info: index exists.''', 'create index i_index on tablename ( columnname )'); prepare stmt @sqlstmt; execute stmt;
Comments
Post a Comment