可重複執行的SQL alter語句
阿新 • • 發佈:2020-01-22
-- 修改通知郵件title欄位 DROP PROCEDURE IF EXISTS `MODIFY_TITLE_COLUMN_IN_NOTICE_MAIL`; DELIMITER // CREATE PROCEDURE `MODIFY_TITLE_COLUMN_IN_NOTICE_MAIL`() BEGIN DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN END; IF EXISTS (SELECT * FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 't_notice_mail' AND column_name ='title') THEN UPDATE t_notice_mail SET title=NULL; ALTER TABLE `t_notice_mail` CHANGE title title varchar(64) COMMENT 'mail title'; END IF; END // DELIMITER ; CALL `MODIFY_TITLE_COLUMN_IN_NOTICE_MAIL`(); DROP PROCEDURE `MODIFY_TITLE_COLUMN_IN_NOTICE_MAIL`;