-- 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;

 

相关文章:

  • 2022-03-08
  • 2022-12-23
  • 2021-11-18
  • 2021-07-14
  • 2022-12-23
  • 2021-10-31
  • 2022-12-23
  • 2021-06-02
猜你喜欢
  • 2022-12-23
  • 2021-11-13
  • 2022-12-23
  • 2022-02-27
  • 2022-12-23
  • 2022-01-04
  • 2021-12-25
相关资源
相似解决方案