判斷欄位是否存在: 判斷索引是否存在: 從這兩段可以看出很多東西,具體可以自己試驗一下 ...
判斷欄位是否存在:
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.columns WHERE table_schema=CurrentDatabase AND table_name = 'rtc_order' AND column_name = 'IfUpSend') THEN 7 ALTER TABLE rtc_order 8 ADD COLUMN `IfUpSend` BIT NOT NULL DEFAULT 0 COMMENT '是否上傳 是否上傳'; 9 END IF; 10 END// 11 DELIMITER ; 12 CALL schema_change();
判斷索引是否存在:
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();
從這兩段可以看出很多東西,具體可以自己試驗一下