时间:2021-07-01 10:21:17 帮助过:2人阅读
判断索引是否存在:
1 DROP PROCEDURE IF EXISTS schema_change;
2 DELIMITER //
3 CREATE PROCEDURE schema_change() BEGIN
4 DECLARE CurrentDatabase VARCHAR(100);
5 SELECT DATABASE() INTO CurrentDatabase;
6 IF NOT EXISTS (SELECT * FROM information_schema.statistics WHERE table_schema=CurrentDatabase AND table_name = ‘rtc_phototype‘ AND index_name = ‘index_name‘) THEN
7 ALTER TABLE `rtc_Phototype` ADD INDEX index_name ( `imgtype` );
8 END IF;
9 END//
10 DELIMITER ;
11 CALL schema_change();
从这两段可以看出很多东西,具体可以自己试验一下
mysql 判断表字段或索引是否存在
标签: