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?');
  • 相关阅读:
    阅读13-17章
    阅读<构建之法>10、11、12章
    作业5.2
    作业5.1
    作业四:构建之法的困惑和思考(5-7)
    做汉堡
    作业三:构建之法的困惑和思考(1-5)
    实验二 合作:王宏财 http://www.cnblogs.com/wanghongcai/
    实验一--四则运算
    数独九宫格
  • 原文地址:https://www.cnblogs.com/guochunyi/p/5072493.html
Copyright © 2011-2022 走看看