mysql索引是否真正起作用
发布网友
发布时间:2022-04-07 14:24
我来回答
共1个回答
热心网友
时间:2022-04-07 15:54
判断字段是否存在:
DROP PROCEDURE IF EXISTS schema_change; DELIMITER // CREATE PROCEDURE schema_change() BEGIN DECLARE CurrentDatabase VARCHAR(); SELECT DATABASE() INTO CurrentDatabase; IF NOT EXISTS (SELECT * FROM information_schema.columns WHERE table_schema=CurrentDatabase AND table_name = 'rtc_order' AND column_name = 'IfUpSend') THEN ALTER TABLE rtc_order ADD COLUMN `IfUpSend` BIT NOT NULL DEFAULT COMMENT '是否上传 是否上传'; END IF; END// DELIMITER ; CALL schema_change();
判断索引是否存在:
DROP PROCEDURE IF EXISTS schema_change; DELIMITER // CREATE PROCEDURE schema_change() BEGIN DECLARE CurrentDatabase VARCHAR(); SELECT DATABASE() INTO CurrentDatabase; IF NOT EXISTS (SELECT * FROM information_schema.statistics WHERE table_schema=CurrentDatabase AND table_name = 'rtc_phototype' AND index_name = 'index_name') THEN ALTER TABLE `rtc_Phototype` ADD INDEX index_name ( `imgtype` ); END IF; END// DELIMITER ; CALL schema_change();
从这两段可以看出很多东西,具体可以自己试验一下