`

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

阅读更多
里面包含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.   
分享到:
评论

相关推荐

    MySQL8从入门到精通视频.zip

    网盘文件永久链接 第1讲 初始MySQL 第2讲 MySQL的安装与配置 第3讲 数据库的基本操作 第4讲 数据表的基本操作 第5讲 数据类型和运算符 第6讲 MySQL函数 第7讲 查询数据 ...课本源代码 MySQL常用命令大全

    漫画SQL-mysql 必修课视频课程下载整理.zip

    14. **存储过程与触发器**:介绍存储过程和触发器的定义与调用,以及它们在数据库管理和自动化任务中的应用。 15. **事务处理**:理解ACID属性,学习如何使用BEGIN、COMMIT、ROLLBACK语句进行事务控制。 16. **...

    mysql-5.6.15.tar.gz

    下载的`.tar.gz`文件包含了编译和安装MySQL 5.6.15所需的所有源代码和文档。解压后,你需要遵循一系列步骤来编译和配置MySQL,这通常包括配置选项设置、编译、安装以及初始化数据库。在Linux系统中,这些步骤可能...

    mysql-standard-4.0.5-beta.tar.gz

    此外,还增强了对存储过程、触发器和视图等高级数据库功能的支持,使得MySQL更加接近于一个企业级的关系型数据库管理系统。 在"mysql-4.0.5-beta"这个子目录中,我们可以预期找到MySQL服务器的源代码、安装脚本、...

    mysql-5.1.73-winx64.rar

    在提供的压缩包中,"MySQL_For_Windows_x64_PChome下载介绍.txt"可能包含关于如何在Windows 64位系统上安装和配置MySQL的指南,"PCHome_download.html"可能是下载页面的源代码或一个链接页面,而"mysql-5.1.73-winx...

    课堂课件mysql教程PPT,针对初学者.pdf

    MySQL的特征包括性能快捷、优化SQL语言、易于使用、多线程和可靠性、多用户支持、可移植性和开放源代码等。 MySQL的优点 * 数据按一定的数据模型组织、描述和储存 * 可为各种用户共享 * 冗余度较小,节省存储空间 ...

    微软SQL和MySQL数据库实战训练营

    而MySQL则是一款轻量级、开放源代码的数据库系统,因其高效、易用和成本效益而广受开发者喜爱,常用于Web应用程序。 在实战训练营中,学员将学习如何使用SQL进行CRUD操作,即创建(Create)、读取(Retrieve)、更新...

    数据库资料

    学习Oracle,你需要了解SQL语法、PL/SQL编程、数据库设计、索引、存储过程、触发器、事务管理和数据库备份与恢复等。Oracle还提供了如SQL Developer这样的工具,方便用户进行数据库管理和开发。 再来说说MySQL,它...

    Microsoft Azure Function Apps 操作大全.docx

    Azure Functions 是一种事件驱动的服务,它允许开发者编写只在特定事件触发时执行的代码片段,这些事件可以来自各种源,如云消息、存储队列或 HTTP 请求。Function Apps 是 Azure Functions 的容器,它为多个函数...

    shujuku.rar_visual c_数据库 课件

    5. 存储过程和触发器:讨论存储过程的优点,如何在Visual C++中调用存储过程,并解释触发器在数据库事件中的作用。 6. 数据库事务和安全性:讲解事务的ACID属性(原子性、一致性、隔离性和持久性),以及如何在C++...

    APSchedurler

    1. **多调度器引擎**:它支持三种不同的调度器引擎——基于日期(DateBasedJobStore)、基于内存(MemoryJobStore)和基于数据库(如SQLite、MySQL等)的JobStore。这使得你可以根据应用需求选择最适合的存储方式。 ...

Global site tag (gtag.js) - Google Analytics