时间:2021-07-01 10:21:17 帮助过:28人阅读
Mysql
DELIMITER ;; DROP PROCEDURE IF EXISTS COLUMNADD; CREATE DEFINER=`root`@`%` PROCEDURE `COLUMNADD`(TBNAME VARCHAR(30),COLNAME VARCHAR(32),COLTYPE VARCHAR(64)) BEGIN DECLARE P_STR VARCHAR(300); IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME = TBNAME AND COLUMN_NAME =COLNAME) THEN -- 判断列是否存在 SET P_STR= CONCAT(‘ALTER TABLE ‘,TBNAME,‘ ADD ‘,COLNAME ,‘ ‘,COLTYPE); SET @SQL = P_STR; PREPARE STMT FROM @SQL; EXECUTE STMT; DEALLOCATE PREPARE STMT; END IF; END;; DELIMITER ; -- 调用该存储过程 CALL COLUMNADD(‘LF_WCD_P1‘,‘WCD_URLP1‘,‘VARCHAR(64) NOT NULL DEFAULT ‘‘‘‘‘);
数据库表添加新字段(支持重复执行)
标签:har media procedure 重复执行 null 执行 nbsp format default