具体的upgrade
脚本如下:
动态删除索引
drop procedure if exists upgrade; delimiter $$ create procedure upgrade() begin -- resource.audio_attribute if exists(select * from information_schema.statistics where table_schema = 'resource' and table_name = 'audio_attribute' and index_name = 'resource_publish_resource_id_index') then alter table `audio_attribute` drop index resource_publish_resource_id_index; end if; end$$ delimiter ; call upgrade(); drop procedure if exists upgrade;
动态添加字段
drop procedure if exists upgrade; delimiter $$ create procedure upgrade() begin -- homework.homework_question_group.from_id if not exists(select * from information_schema.columns where table_schema = 'homework' and table_name = 'homework_question_group' and column_name = 'from_id') then alter table `homework_question_group` add column from_id varchar(50) null; end if; -- homework.homework_question_group.question_type if not exists(select * from information_schema.columns where table_schema = 'homework' and table_name = 'homework_question_group' and column_name = 'question_type') then alter table `homework_question_group` add column question_type varchar(50) null; end if; -- homework.homework_question_group.difficulty if not exists(select * from information_schema.columns where table_schema = 'homework' and table_name = 'homework_question_group' and column_name = 'difficulty') then alter table `homework_question_group` add column difficulty varchar(50) null; end if; end$$ delimiter ; call upgrade(); drop procedure if exists upgrade;
其他语法类似,主要区分exists
和not exists
的用法。
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对移动技术网的支持。如果你想了解更多相关内容请查看下面相关链接
如对本文有疑问, 点击进行留言回复!!
服务器Centos部署MySql并连接Navicat过程详解
网友评论