时间:2021-07-01 10:21:17 帮助过:27人阅读
这个存储过程主要是校验表字段是否存在
2 判断库是否存在
1 CREATE DATABASE IF NOT EXISTS `fqmanagesysdb` /*!40100 DEFAULT CHARACTER SET utf8 */; 2 USE `fqmanagesysdb`;View Code
3 判断表是否存在创建
1 CREATE TABLE IF NOT EXISTS `userinfo` ( 2 `id` int(11) NOT NULL DEFAULT ‘1‘, 3 `user_name` varchar(255) NOT NULL, 4 `user_pwd` varchar(255) NOT NULL, 5 `user_type` tinyint(4) NOT NULL DEFAULT ‘2‘, 6 `Power` int(11) NOT NULL DEFAULT ‘0‘, 7 `DeptID` int(11) NOT NULL DEFAULT ‘0‘ 8 PRIMARY KEY (`user_name`,`user_type`), 9 KEY `userinfo_user_name_index` (`user_name`) 10 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;View Code
4 判断视图是否存在的
1 DROP VIEW IF EXISTS `allcode_view`;
5 判断存储过程是否存在
1 drop procedure if exists procedure_split;
6 插入初始化数据
1 INSERT INTO `userinfo` (id,user_name,user_pwd,user_type,Power,DeptID) select ‘1‘, ‘admin‘, ‘admin‘, ‘1‘, ‘0‘, ‘1‘ from DUAL where not exists (select * from userinfo where user_name = ‘admin‘);
7 判断触发器是否存在
1 DROP TRIGGER IF EXISTS `trigger_delete_fucode`;
8 向表里添加新的字段
1 SELECT count(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=‘fqmanagesysdb‘ AND table_name=‘userinfo‘ AND COLUMN_NAME=‘BrokerID‘ into @ret; 2 call pro_upgrade(@ret,‘alter table userinfo ADD COLUMN BrokerID varchar(255) NOT NULL ‘);
这里用到了上面的存储过程,mysql里面在非存储过程里面不支持if not exists的判断
9 其他
待补充……
mysql 下数据库升级脚本的编写
标签:info exist procedure roc table power 图片 alter view