日期:2014-05-16 浏览次数:20473 次
BEGIN DECLARE tableNameXX VARCHAR(100); DECLARE indexNameXX VARCHAR(100); DECLARE sqll VARCHAR(1000); DECLARE countIndexXX INT; DECLARE done int; DECLARE needUpdateC CURSOR FOR SELECT table_name,INDEX_NAME,COUNT(1) ct FROM information_schema.`STATISTICS` WHERE seq_in_index=1 AND table_schema='test' AND INDEX_NAME!='PRIMARY' GROUP BY table_name,column_name HAVING ct >=2; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1; OPEN needUpdateC; cursor_loop:LOOP FETCH needUpdateC into tableNameXX,indexNameXX,countIndexXX; SET sqll=CONCAT_ws(' ','drop index ',indexNameXX ,' on ',tableNameXX); IF done=1 THEN LEAVE cursor_loop; END IF; SET @sql=sqll; PREPARE s1 FROM @sql; EXECUTE s1; DEALLOCATE PREPARE s1; END LOOP cursor_loop; CLOSE needUpdateC; END