sql可重复执行语句例子

1.添加字段

SET @add_key_type_to_report = (SELECT IF(
    (SELECT count(1)
        FROM INFORMATION_SCHEMA.COLUMNS
        WHERE table_name = 'report'
        AND table_schema = DATABASE()
        AND column_name = 'key_type'
    ) > 0,
    "select 1",
    "alter table report add `key_type` int(4) NOT NULL COMMENT '认证key类型 --1 group类型 2 sn类型'"
));
PREPARE stmt FROM @add_key_type_to_report;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

 

-- 可重复性添加索引

SET @add_index_idx_group_id_location_name_to_plan_location = (SELECT IF(
    (SELECT count(1)
        FROM INFORMATION_SCHEMA.STATISTICS

     WHERE table_name = 'plan_location'
        AND table_schema = DATABASE()
        AND index_name = 'idx_group_id_location_name'
    ) > 0,
    "select 1",
    "alter table plan_location add INDEX idx_group_id_location_name(`location_name`, `group_id`)"
));
PREPARE stmt FROM @add_index_idx_group_id_location_name_to_plan_location;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

 -- 插入可重复性语句

INSERT IGNORE INTO `intl_api_msg_en` (`code`, `msg`) VALUES (7036, 'Group or sub group have bound template,need to remain the binding?');

 

转载于:https://www.cnblogs.com/guochunyi/p/5072493.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值