论坛首页 综合技术论坛

MySql源代码备份——触发器、存储过程

浏览 3828 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-09-12  
里面包含mysql存储过程中的变量查询赋等等问题。。。。。。
sql 代码
  1. /*   
  2. SQLyog 企业版 - MySQL GUI v5.02   
  3. 主机 - 5.0.27-community-nt : 数据库 - car110   
  4. *********************************************************************   
  5. 服务器版本 : 5.0.27-community-nt   
  6. */   
  7.   
  8.   
  9. /*数据表 `bar_apply_bar` 的表结构*/   
  10.   
  11. CREATE TABLE `bar_apply_bar` (   
  12.   `id` int(32) NOT NULL auto_increment,   
  13.   `title` varchar(255) NOT NULL,   
  14.   `content` text,   
  15.   `img_href` varchar(255) default NULL,   
  16.   `user_id` int(32) NOT NULL default '0',   
  17.   `ip` varchar(15) NOT NULL,   
  18.   `state` tinyint(1) NOT NULL default '0' ,   
  19.   PRIMARY KEY  (`id`)   
  20. ) ;   
  21.   
  22. /*数据表 `bar_apply_bar` 的数据*/   
  23.   
  24. /*数据表 `bar_apply_king` 的表结构*/   
  25.   
  26. CREATE TABLE `bar_apply_king` (   
  27.   `id` int(32) NOT NULL auto_increment,   
  28.   `bar_id` int(32) NOT NULL,   
  29.   `content` text,   
  30.   `realName` varchar(50) default NULL,   
  31.   `tel` varchar(50) default NULL,   
  32.   `email` varchar(100) default NULL,   
  33.   `state` tinyint(1) NOT NULL default '0',   
  34.   PRIMARY KEY  (`id`)   
  35. );   
  36.   
  37. /*数据表 `bar_apply_king` 的数据*/   
  38.   
  39. /*数据表 `bar_bar` 的表结构*/   
  40.   
  41. CREATE TABLE `bar_bar` (   
  42.   `id` int(32) NOT NULL auto_increment,   
  43.   `title` varchar(50) NOT NULL,   
  44.   `subjects` int(16) NOT NULL default '0' ,   
  45.   `ties` int(16) NOT NULL default '0' ,   
  46.   `pnum` int(16) NOT NULL default '0',   
  47.   `sort_id` int(32) NOT NULL,   
  48.   PRIMARY KEY  (`id`)   
  49. ) ;   
  50.   
  51.   
  52.   
  53. /*数据表 `bar_king` 的表结构*/   
  54.   
  55. CREATE TABLE `bar_king` (   
  56.   `id` int(32) NOT NULL auto_increment,   
  57.   `user_id` int(32) NOT NULL,   
  58.   `bar_id` int(32) NOT NULL,   
  59.   PRIMARY KEY  (`id`)   
  60. );   
  61.   
  62.   
  63.   
  64. /*数据表 `bar_sort` 的表结构*/   
  65.   
  66. CREATE TABLE `bar_sort` (   
  67.   `id` int(32) NOT NULL auto_increment,   
  68.   `title` varchar(50) NOT NULL,   
  69.   `pnum` int(16) NOT NULL default '0',   
  70.   `fid` int(32) NOT NULL default '0' ,   
  71.   PRIMARY KEY  (`id`)   
  72. );   
  73.   
  74.   
  75.   
  76. /*数据表 `bar_tie` 的表结构*/   
  77.   
  78. CREATE TABLE `bar_tie` (   
  79.   `id` int(32) NOT NULL auto_increment,   
  80.   `title` varchar(50) NOT NULL,   
  81.   `content` text,   
  82.   `img_href` varchar(255) default NULL,   
  83.   `user_type` tinyint(1) NOT NULL default '0' ,   
  84.   `user_id` int(32) NOT NULL,   
  85.   `ip` varchar(15) default NULL,   
  86.   `itime` timestamp NOT NULL,   
  87.   `bar_id` int(32) NOT NULL,   
  88.   `clicks` int(32) NOT NULL default '0',   
  89.   `reverts` int(32) NOT NULL default '0',   
  90.   `top` tinyint(1) NOT NULL default '0' ,   
  91.   `jing` tinyint(1) NOT NULL default '0' ,   
  92.   `fid` int(32) NOT NULL default '0' ,   
  93.   PRIMARY KEY  (`id`)   
  94. ) ;   
  95.   
  96.   
  97.   
  98.   
  99.   
  100.   
  101.   
  102.   
  103.   
  104.   
  105.   
  106. /*数据表 `bar_bar` 的触发器结构*/   
  107.   
  108. DELIMITER $$;   
  109.   
  110. DROP TRIGGER `tri_bar_del`$$   
  111.   
  112. CREATE TRIGGER `tri_bar_del` BEFORE DELETE ON `bar_bar` FOR EACH ROWBEGIN   
  113. delete from bar_tie where bar_id=Old.id and fid=0;   
  114. END$$   
  115.   
  116.   
  117. DELIMITER ;$$   
  118.   
  119.   
  120.   
  121.   
  122. /*数据表 `bar_sort` 的触发器结构*/   
  123.   
  124. DELIMITER $$;   
  125.   
  126. DROP TRIGGER `tri_bar_sort_del`$$   
  127.   
  128. CREATE TRIGGER `tri_bar_sort_del` BEFORE DELETE ON `bar_sort` FOR EACH ROWBEGIN   
  129. delete from bar_bar where sort_id=Old.id;   
  130. END$$   
  131.   
  132.   
  133. DELIMITER ;$$   
  134.   
  135.   
  136.   
  137.   
  138. /*数据表 `bar_tie` 的触发器结构*/   
  139.   
  140. DELIMITER $$;   
  141.   
  142. DROP TRIGGER `tri_tie_add`$$   
  143.   
  144. CREATE TRIGGER `tri_tie_add` AFTER INSERT ON `bar_tie` FOR EACH ROWBEGIN   
  145. if New.fid=0 then  
  146. update bar_bar set subjects = subjects+1 where id = New.bar_id;   
  147. end if;   
  148. update bar_bar set ties = ties+1 where id = New.bar_id;   
  149. END$$   
  150.   
  151.   
  152. DELIMITER ;$$   
  153.   
  154.   
  155.   
  156. /*过程 `proc_tie_del` 的过程结构*/   
  157.   
  158. drop procedure if exists `proc_tie_del`;   
  159.   
  160. DELIMITER $$;   
  161.   
  162. CREATE DEFINER=`root`@`localhost` PROCEDURE `proc_tie_del`(IN xid int)   
  163. BEGIN  
  164. declare delrows int;   
  165. if exists (select * from bar_tie where id=xid and fid=0) then  
  166. select count(*) from bar_tie where fid=xid into delrows;   
  167. delete from bar_tie where fid=xid;   
  168. update bar_bar set ties=ties-delrows-1;   
  169. update bar_bar set subjects=subjects-1;   
  170. elseif exists (select * from bar_tie where id=xid) then  
  171. update bar_bar set ties=ties-1;   
  172. end if;   
  173. delete from test where id=xid;   
  174. END$$   
  175.   
  176. DELIMITER ;$$   
  177.   
论坛首页 综合技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics