标签:info exist procedure roc table power 图片 alter view
1 升级时必须得存储过程
1 /**/ 2 drop procedure if exists pro_upgrade; 3 DELIMITER // 4 CREATE DEFINER=`root`@`%` PROCEDURE `pro_upgrade`( 5 exec_boolen int , 6 sql_str VARCHAR(256) 7 ) 8 BEGIN 9 # 执行sql 操作 10 IF sql_str <>‘‘ 11 THEN 12 set @sql1 = sql_str; 13 set @bexec = exec_boolen; 14 15 if @bexec = 0 16 then 17 PREPARE execsql FROM @sql1; 18 EXECUTE execsql ; 19 end if; 20 END IF; 21 END// 22 DELIMITER ;
这个存储过程主要是校验表字段是否存在
2 判断库是否存在
1 CREATE DATABASE IF NOT EXISTS `fqmanagesysdb` /*!40100 DEFAULT CHARACTER SET utf8 */; 2 USE `fqmanagesysdb`;
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;
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 其他
待补充……
标签:info exist procedure roc table power 图片 alter view
原文地址:http://www.cnblogs.com/a9999/p/7890238.html