mysql 可重复插入、创建语句

-- 插入一条数据 判断是否存在
 INSERT INTO `evcall`.`evcall_const` ( `constName`, `constValue`, `constOrder`, `constType`, `isHidden`, `constMeaning`) 
 SELECT 'xjz_update_file_millis', '1524051782084', '0', '5', '0', '更新时间'
 FROM DUAL WHERE NOT EXISTS(SELECT constName FROM `evcall`.`evcall_const` WHERE constName='xjz_update_file_millis');

 

-- 创建表
CREATE TABLE IF NOT EXISTS `xjw_business_handling` (
   `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增ID',
   `uuid` varchar(128) NOT NULL COMMENT '唯一识别号'
   PRIMARY KEY (`id`)
 ) ENGINE=InnoDB AUTO_INCREMENT=250 DEFAULT CHARSET=utf8mb4 COMMENT='业务';

 

-- 新增列判断 只能使用 存储过程来判断
CREATE PROCEDURE Temp_test()
BEGIN
    IF NOT EXISTS (
            SELECT 1 
                FROM  information_schema.COLUMNS 
                WHERE TABLE_SCHEMA='evcall' 
                AND TABLE_NAME='evcall_business' 
                AND COLUMN_NAME='businessOrder123'
    )
    THEN 
        ALTER TABLE evcall_business ADD COLUMN `businessOrder123` int(11) NOT NULL DEFAULT '999' ;
    END IF;
END;

CALL Temp_test();

 

 

posted @ 2018-08-06 15:39  sp950622  阅读(260)  评论(0编辑  收藏  举报