- 11lingxian
- 等级: 初级会员
- 性别:
- 文章: 8
- 积分: 40
- 来自: 青岛
|
里面包含mysql存储过程中的变量查询赋等等问题。。。。。。
sql 代码
- /*
- SQLyog 企业版 - MySQL GUI v5.02
- 主机 - 5.0.27-community-nt : 数据库 - car110
- *********************************************************************
- 服务器版本 : 5.0.27-community-nt
- */
-
-
- /*数据表 `bar_apply_bar` 的表结构*/
-
- CREATE TABLE `bar_apply_bar` (
- `id` int(32) NOT NULL auto_increment,
- `title` varchar(255) NOT NULL,
- `content` text,
- `img_href` varchar(255) default NULL,
- `user_id` int(32) NOT NULL default '0',
- `ip` varchar(15) NOT NULL,
- `state` tinyint(1) NOT NULL default '0' ,
- PRIMARY KEY (`id`)
- ) ;
-
- /*数据表 `bar_apply_bar` 的数据*/
-
- /*数据表 `bar_apply_king` 的表结构*/
-
- CREATE TABLE `bar_apply_king` (
- `id` int(32) NOT NULL auto_increment,
- `bar_id` int(32) NOT NULL,
- `content` text,
- `realName` varchar(50) default NULL,
- `tel` varchar(50) default NULL,
- `email` varchar(100) default NULL,
- `state` tinyint(1) NOT NULL default '0',
- PRIMARY KEY (`id`)
- );
-
- /*数据表 `bar_apply_king` 的数据*/
-
- /*数据表 `bar_bar` 的表结构*/
-
- CREATE TABLE `bar_bar` (
- `id` int(32) NOT NULL auto_increment,
- `title` varchar(50) NOT NULL,
- `subjects` int(16) NOT NULL default '0' ,
- `ties` int(16) NOT NULL default '0' ,
- `pnum` int(16) NOT NULL default '0',
- `sort_id` int(32) NOT NULL,
- PRIMARY KEY (`id`)
- ) ;
-
-
-
- /*数据表 `bar_king` 的表结构*/
-
- CREATE TABLE `bar_king` (
- `id` int(32) NOT NULL auto_increment,
- `user_id` int(32) NOT NULL,
- `bar_id` int(32) NOT NULL,
- PRIMARY KEY (`id`)
- );
-
-
-
- /*数据表 `bar_sort` 的表结构*/
-
- CREATE TABLE `bar_sort` (
- `id` int(32) NOT NULL auto_increment,
- `title` varchar(50) NOT NULL,
- `pnum` int(16) NOT NULL default '0',
- `fid` int(32) NOT NULL default '0' ,
- PRIMARY KEY (`id`)
- );
-
-
-
- /*数据表 `bar_tie` 的表结构*/
-
- CREATE TABLE `bar_tie` (
- `id` int(32) NOT NULL auto_increment,
- `title` varchar(50) NOT NULL,
- `content` text,
- `img_href` varchar(255) default NULL,
- `user_type` tinyint(1) NOT NULL default '0' ,
- `user_id` int(32) NOT NULL,
- `ip` varchar(15) default NULL,
- `itime` timestamp NOT NULL,
- `bar_id` int(32) NOT NULL,
- `clicks` int(32) NOT NULL default '0',
- `reverts` int(32) NOT NULL default '0',
- `top` tinyint(1) NOT NULL default '0' ,
- `jing` tinyint(1) NOT NULL default '0' ,
- `fid` int(32) NOT NULL default '0' ,
- PRIMARY KEY (`id`)
- ) ;
-
-
-
-
-
-
-
-
-
-
-
- /*数据表 `bar_bar` 的触发器结构*/
-
- DELIMITER $$;
-
- DROP TRIGGER `tri_bar_del`$$
-
- CREATE TRIGGER `tri_bar_del` BEFORE DELETE ON `bar_bar` FOR EACH ROWBEGIN
- delete from bar_tie where bar_id=Old.id and fid=0;
- END$$
-
-
- DELIMITER ;$$
-
-
-
-
- /*数据表 `bar_sort` 的触发器结构*/
-
- DELIMITER $$;
-
- DROP TRIGGER `tri_bar_sort_del`$$
-
- CREATE TRIGGER `tri_bar_sort_del` BEFORE DELETE ON `bar_sort` FOR EACH ROWBEGIN
- delete from bar_bar where sort_id=Old.id;
- END$$
-
-
- DELIMITER ;$$
-
-
-
-
- /*数据表 `bar_tie` 的触发器结构*/
-
- DELIMITER $$;
-
- DROP TRIGGER `tri_tie_add`$$
-
- CREATE TRIGGER `tri_tie_add` AFTER INSERT ON `bar_tie` FOR EACH ROWBEGIN
- if New.fid=0 then
- update bar_bar set subjects = subjects+1 where id = New.bar_id;
- end if;
- update bar_bar set ties = ties+1 where id = New.bar_id;
- END$$
-
-
- DELIMITER ;$$
-
-
-
- /*过程 `proc_tie_del` 的过程结构*/
-
- drop procedure if exists `proc_tie_del`;
-
- DELIMITER $$;
-
- CREATE DEFINER=`root`@`localhost` PROCEDURE `proc_tie_del`(IN xid int)
- BEGIN
- declare delrows int;
- if exists (select * from bar_tie where id=xid and fid=0) then
- select count(*) from bar_tie where fid=xid into delrows;
- delete from bar_tie where fid=xid;
- update bar_bar set ties=ties-delrows-1;
- update bar_bar set subjects=subjects-1;
- elseif exists (select * from bar_tie where id=xid) then
- update bar_bar set ties=ties-1;
- end if;
- delete from test where id=xid;
- END$$
-
- DELIMITER ;$$
-
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
|