zoukankan      html  css  js  c++  java
  • 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?');
  • 相关阅读:
    Nginx下载服务器配置文件
    php7连接mysql测试代码
    Vagrant 构建 Linux 开发环境
    清理buffer/cache/swap的方法梳理
    【12】
    python全栈目录
    Chrome启动后打开第一个网页很慢的解决方案
    Pycharm快捷键
    TEst
    1、Linux命令随笔
  • 原文地址:https://www.cnblogs.com/guochunyi/p/5072493.html
Copyright © 2011-2022 走看看