zoukankan      html  css  js  c++  java
  • Mysql 使用存储过程添加新字段

    -- 1, 注意SQL 语句开始处不要空格
    -- 2, 在使用 [--] 进行注释时,后面请加空格
    USE `test`;
    
    -- lastUpdateTime
    drop procedure if exists schema_change;
    delimiter ';;';
    create procedure schema_change() begin
    if exists (select * from information_schema.columns where table_name = 't_my_table' and column_name = 'lastUpdateTime') then
            alter table t_my_table drop column lastUpdateTime;
    end if;
    alter table t_my_table add column lastUpdateTime  datetime DEFAULT NULL;
    end;;
    delimiter ';';
    call schema_change();
    -- myScore 
    drop procedure if exists schema_change;
    delimiter ';;';
    create procedure schema_change() begin
    if exists (select * from information_schema.columns where table_name = 't_my_table' and column_name = 'myScore') then
            alter table t_my_table drop column myScore;
    end if;
    alter table t_my_table add column myScore int(11) DEFAULT '0';
    end;;
    delimiter ';';
    call schema_change();
    drop procedure if exists schema_change;
  • 相关阅读:
    phpHttp请求头
    第八周学习总结
    梦断代码阅读笔记-03
    第七周学习总结
    针对自己开发项目的NABC的认知
    梦断代码阅读笔记
    第六周学习总结
    第五周学习总结
    移动端疫情展示
    第四周学习总结
  • 原文地址:https://www.cnblogs.com/web1992/p/4812402.html
Copyright © 2011-2022 走看看