一个mysql存储记录_MySQL
程序员文章站
2024-01-01 22:58:58
...
bitsCN.com
一个mysql存储记录
01BEGIN02#-------------------------tbsysinfo03prepare tempSql from "ALTER TABLE `tbsysinfo` ADD COLUMN `szClass` varchar(2) NULL DEFAULT '00' AFTER `nType`";04execute tempSql; 0506#-------------------------netCard07prepare tempSql from "CREATE TABLE `tbNetCfg` ( `nID` INT(10) NULL AUTO_INCREMENT, `szCapture` VARCHAR(100) NOT NULL DEFAULT '0', `szServiceName` VARCHAR(100) NOT NULL DEFAULT '0', `szServiceIP` VARCHAR(100) NOT NULL DEFAULT '0', PRIMARY KEY (`nID`))COLLATE='utf8_general_ci' ENGINE=InnoDB;";08execute tempSql;09SELECT szAdminIP into @szAdminIp FROM `tbsyscfg`;10Select szName into @card1 from tbnetcards where nType = 1 limit 1;11Select szName into @card2 from tbnetcards where nType = 2 limit 1;12if @card2 is NULL THEN13 set @card2 = @card1;14end if;15insert into tbNetCfg values(NULL,@card1,@card2,@szAdminIp);1617#-------------------------limitSpeed18prepare tmpSqlToRun from "ALTER TABLE `tblimitspeed` ADD COLUMN `nWeekDay` smallint(1) NOT NULL DEFAULT 1 AFTER `nTimeZDef`,ADD COLUMN `group` smallint(1) NULL DEFAULT 1 AFTER `nWeekDay`,ADD PRIMARY KEY (`nWeekDay`)";19execute tmpSqlToRun;20select nWeekDay,`group`,nBandWidth,nTimeZDef,nTime0,nTime1,nTime2,nTime3,nTime4,nTime5,nTime6,nTime7,nTime8,nTime9,nTime10,nTime11,nTime12,nTime13,nTime14,nTime15,nTime16,nTime17,nTime18,nTime19,nTime20,nTime21,nTime22,nTime2321into @nWeekDay,@groupp,@BandWidth,@nTimeZDef,@nTime0,@nTime1,@nTime2,@nTime3,@nTime4,@nTime5,@nTime6,@nTime7,@nTime8,@nTime9,@nTime10,@nTime11,@nTime12,@nTime13,@nTime14,@nTime15,@nTime16,@nTime17,@nTime18,@nTime19,@nTime20,@nTime21,@nTime22,@nTime2322from tblimitspeed;23insert into tblimitspeed values(@nTime0,@nTime1,@nTime2,@nTime3,@nTime4,@nTime5,@nTime6,@nTime7,@nTime8,@nTime9,@nTime10,@nTime11,@nTime12,@nTime13,@nTime14,@nTime15,@nTime16,@nTime17,@nTime18,@nTime19,@nTime20,@nTime21,@nTime22,@nTime23,@BandWidth,@nTimeZDef,2,@groupp); 24END
说明
数据库升级写的一个存储过程,记录一下,以前每次写存储过程都需要全网找资料,很烦。
执行修改表结构语句:
prepare tempSql from "ALTER TABLE tbsysinfo ADD COLUMN szClass varchar(2) NULL DEFAULT '00' AFTER nType"; execute tempSql;
结果赋值:
Select szName into @card1 from tbnetcards where nType = 1 limit 1; set @card2 = @card1; 未使用的一种 DECLARE cnt INT DEFAULT 0; select count(*) into cnt from test_tbl; select cnt;
IF语法:
if @card2 is NULL THEN set @card2 = @card1; end if;
最后limitSpeed 部分,20多个字段,没找到简单的多列赋值的方法,蠢办法一个个赋值,真是--!!
bitsCN.com推荐阅读
-
一个mysql存储记录_MySQL
-
select-mysql 嵌套查询,一个表的多个字段 作为另一个表的条件,求高手
-
mysql存储过程实现split示例_MySQL
-
在Ubuntu下的MySQL数据库如何更改存储位置_MySQL
-
mysql-为什么我项目本地和服务器上,一个数据库的sleep会被释放,一个不会
-
从一个错误语句看Mysql 数据库命名规范
-
mysql分组查询查询每个组前面40条数据里面某个字段不能连续超过8条为空的记录,请大神指导
-
读MySQL技术内幕:InnoDB存储引擎
-
一个简单的php实现的MySQL数据浏览器_php实例
-
把sqlserver中的存储过程注释后创建到mysql中