`
zhengdl126
  • 浏览: 2538970 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类

mysql触发器

阅读更多

show errors;

SHOW TRIGGER;

DROP TRIGGER t1;


--------------------------创建触发器 :
语法:

   1. CREATE TRIGGER trigger_name trigger_time trigger_event ON tbl_name 
   2. FOR EACH ROW  
   3. BEGIN 
   4.  trigger_stmt 
   5. END; 

CREATE TRIGGER trigger_name trigger_time trigger_event ON tbl_name
FOR EACH ROW
BEGIN
 trigger_stmt
END;


大写的为关键字
trigger_name:触发器的名字,我常用的命名规则t_name_tableName_(b|a)(i|u|d),t:触发器标识,name:英文名,tableName:表名,b

(BEFORE):标识是触发事件之前,a(AFTER):标识触发事件之后,i(insert): 标识insert事件,u(update):标识update事件,d(delete):标识

delete事件;
trigger_time:触发时间(BEFORE或AFTER)
trigger_event:事件名(insert或update或delete)
tbl_name:表名(必须是永久性表)
trigger_stmt:执行语句(可以是复合语名),使用别名OLD和NEW,能够引用与触发程序相关的表中的列。


----------------------删除解发器
语法:
DROP TRIGGER [schema_name.]trigger_name;
注意:以上操作均需SUPER权限
示例:

   1. DROP TRIGGER t_wiley_hotelComment_bu; 
   2. delimiter // 
   3. CREATE TRIGGER t_wiley_hotelComment_bu BEFORE UPDATE ON hotel_comment 
   4. FOR EACH ROW 
   5. BEGIN 
   6.     IF OLD.ispass=0 && NEW.ispass=1 THEN 
   7.        UPDATE hotel_info SET

sumcomment=sumcomment+1,sumconsume=sumconsume+NEW.consume,sumservice=sumservice+NEW.service,

sumroom=sumroom+NEW.room,sumentiron=sumentiron+NEW.entironment,total=total+(NEW.service+NEW.room+NEW.entironment) WHERE

hotel_id=NEW.hotel_id; 
   8.   ELSEIF OLD.ispass=1 && NEW.ispass=0 THEN 
   9.      UPDATE hotel_info SET sumcomment=sumcomment-1,sumconsume=sumconsume-NEW.consume,sumservice=sumservice-NEW.service,

sumroom=sumroom-NEW.room,sumentiron=sumentiron-NEW.entironment,total=total-(NEW.service+NEW.room+NEW.entironment) WHERE

hotel_id=NEW.hotel_id; 
  10.   END IF; 
  11. END;// 
  12. delimiter ; 

DROP TRIGGER t_wiley_hotelComment_bu;
delimiter //
CREATE TRIGGER t_wiley_hotelComment_bu BEFORE UPDATE ON hotel_comment
FOR EACH ROW
BEGIN
    IF OLD.ispass=0 && NEW.ispass=1 THEN
       UPDATE hotel_info SET sumcomment=sumcomment+1,sumconsume=sumconsume+NEW.consume,sumservice=sumservice+NEW.service,

sumroom=sumroom+NEW.room,sumentiron=sumentiron+NEW.entironment,total=total+(NEW.service+NEW.room+NEW.entironment) WHERE

hotel_id=NEW.hotel_id;
  ELSEIF OLD.ispass=1 && NEW.ispass=0 THEN
     UPDATE hotel_info SET sumcomment=sumcomment-1,sumconsume=sumconsume-NEW.consume,sumservice=sumservice-NEW.service,

sumroom=sumroom-NEW.room,sumentiron=sumentiron-NEW.entironment,total=total-(NEW.service+NEW.room+NEW.entironment) WHERE

hotel_id=NEW.hotel_id;
  END IF;
END;//
delimiter ;


说明:delimiter 改变语句结束符








-----------------------------------------------实例


mysql> CREATE TABLE data (name VARCHAR(255));
Query OK, 0 rows affected (0.09 sec)
mysql> CREATE TABLE chars (count INT(10));
Query OK, 0 rows affected (0.07 sec)
mysql> INSERT INTO chars (count) VALUES (0);
Query OK, 1 row affected (0.00 sec)
mysql> CREATE TRIGGER t1 AFTER INSERT ON
data FOR EACH ROW UPDATE chars SET count
= count + CHAR_LENGTH(NEW.name);
Query OK, 0 rows affected (0.01 sec)

mysql> SHOW TRIGGERSG;
*************************** 1. row ******************
?Trigger: t1
?Event: INSERT
?Table: data
Statement: UPDATE chars SET count = count + CHAR_LENGTH(NEW.name)
Timing: AFTER
?Created: NULL
ql_mode:
1 row in set (0.01 sec)


mysql> INSERT INTO data (name) VALUES ('Sue'), ('Jane');
Query OK, 2 rows affected (0.00 sec)
Records: 2?Duplicates: 0?Warnings: 0

mysql> SELECT * FROM chars;
+-------+
| count |
+-------+
| 7|
+-------+
1 row in set (0.00 sec)




注意:理想情况下,你还需要一个倒转触发器,每当一个记录从源表格中删除时,它从字符总数中减去记录的字符数。这很容易做到,你可以

把它当作练习来完成。提示:应用BEFORE DELETE ON子句是其中一种方法。

 现在,我想建立一个审计记录来追踪对这个表格所做的改变。这个记录将反映表格的每项改变,并向用户说明由谁做出改变以及改变的时间。

我需要建立一个新表格来存储这一信息(表格名:audit),如下所示。



mysql> CREATE TABLE audit (id INT(7),
balance FLOAT, user VARCHAR(50)
NOT NULL, time TIMESTAMP NOT NULL);
Query OK, 0 rows affected (0.09 sec)

  接下来,我将在accounts表格中定义一个触发器。

mysql> CREATE TRIGGER t1 AFTER UPDATEON accounts
FOR EACH ROW INSERT INTO audit (id, balance, user, time)
VALUES (OLD.id, NEW.balance, CURRENT_USER(), NOW());
Query OK, 0 rows affected (0.04 sec)

  注释:accounts表格每经历一次UPDATE,触发器插入(INSERT)对应记录的id、新的余额、当前时间和登录audit表格的用户的名称。

 

 

----------------------------------PPC实例 MYSQL5触发器做数据同步


这几天公司要用触发器作数据同步。数据表有100多张,还不把人累死。所以写了个触发器的自动生成程序:
呵呵:把数据库名表名输入就OK了,生成的代码直接到mysql编译器里运行,触发器就上去了

[群号18255508]   大家一起来研究PHP一起工作

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" c />
<title>无标题文档</title>
<style type="text/css">
<!--
body,td,th {
font-size: 12px;
}
-->
</style>
<script language="javascript">

function res(){
document.getElementById("tab2").value = "pre_"+document.getElementById("tab1").value;
}
</script>
</head>

<body>
<form action="#" method="post" name="form1" target="_blank" id="form1">
  数据库名
    <input name="dbTbaleName" type="text" id="dbTbaleName" value="dbname" />
    <br>
  驱动表
  <input name="tab1" type="text" id="tab1" /> <br>
  被触发的表
  <input name="tab2" type="text" id="tab2"  /><br>
  <input type="submit" name="Submit" value="提交" /><br>
</form>
<?php
/**
* -------------------文档注释------------------------------------------
* 作者*达达*QQ 85089479*email  qianshuei@163.com*
* 创建时间*2006-012-*
* 功能描述*数据同步触发器生成工具*
* 最后修改时间*2006-12-*
* -------------------------------------------------------------------
*/
$dbName = "localhost"; //主机名
$dbUserName = "root"; // 用户名
$dbpassword = "admin"; //密码
$dbTbaleName = $_POST['dbTbaleName']; //数据库名
$tab1 = $_POST['tab1']; //执行的表
$tab2 = $_POST['tab2']; //被触发的表
$conn = mysql_connect($dbName, $dbUserName, $dbpassword) or die("请检查你的主机名数据库用户名和密码");
mysql_select_db($dbTbaleName, $conn) or die("数据库还没有连接");
mysql_select_db("$dbTbaleName");
$result = mysql_query("select * from $tab1")//得到表查询的结果
or die("Query failed: " . mysql_error());
echo("<br>");
$i = 1;//这里是为了替换最后一个列名的,符号所以=1 <>0
echo "create trigger " . $tab1 . "_insert BEFORE INSERT on $tab1<br>";
echo "for each row BEGIN<br>";
echo "INSERT INTO $tab2 SET<br>";
while ($i < mysql_num_fields($result)){//列的数量的循环
  
     $meta = mysql_fetch_field($result);//得到一个关于列的信息的对角
     if (!$meta){
         echo "No information available<br />\n";
         }
   //下面输出的是触发器程序列信息
     echo "<pre>
  `$meta->name`=NEW.$meta->name,
</pre>";
     $i++;
     }
$meta = mysql_fetch_field($result);
echo "<pre>
  `$meta->name`=NEW.$meta->name;
</pre>";
mysql_free_result($result);
echo("END;");

// -----------------------------------------------------------------
$result = mysql_query("select * from $tab1")
or die("Query failed: " . mysql_error());
$i = 1;
if ($i < mysql_num_fields($result)){
  
     $meta = mysql_fetch_field($result);
  
     // -----------------------------------------------------------------
    /**
     * create trigger `tri_del` BEFORE DELETE on `aaa`
     * for each row BEGIN
     * DELETE FROM bbb WHERE id =OLD.id;
     */
    echo("<br>");
  
  
     echo "create trigger " . $tab1 . "_del BEFORE DELETE on $tab1<br>";
     echo "for each row BEGIN<br>";
  
     echo "DELETE FROM $tab2 WHERE $meta->name =OLD.$meta->name;<br>";
     echo("END;");
  
     }
// -----------------------------------------------------------------
echo("<br>");
/**
* create trigger `up_date` BEFORE UPDATE on `aaa`
* for each row BEGIN
* UPDATE bbb set a1 = new.a1 , a2=new.a2 where id = new.id;
* END;
*/
$result = mysql_query("select * from $tab1")
or die("Query failed: " . mysql_error());
/**
* get column metadata
*/
$i = 1;
echo "create trigger " . $tab1 . "_update BEFORE UPDATE on $tab1<br>";
echo "for each row BEGIN<br>";
echo "UPDATE $tab2 SET<br>";
while ($i < mysql_num_fields($result)){
  
     $meta = mysql_fetch_field($result);
     if (!$meta){
         echo "No information available<br />\n";
         }
     echo "<pre>
  `$meta->name`=NEW.$meta->name,
</pre>";
     $i++;
     }
$meta = mysql_fetch_field($result);
echo "<pre>
  `$meta->name`=NEW.$meta->name
</pre>";
mysql_free_result($result);
// -----------------------------
$result = mysql_query("select * from $tab1")
or die("Query failed: " . mysql_error());
$i = 1;
if ($i < mysql_num_fields($result)){
  
     $meta = mysql_fetch_field($result);
     echo("where $meta->name = new.$meta->name;<br>");
  
  
     echo("END;");
  
     }
?>

 

 

 

=---------------------------------------实例

--
-- Triggers `timecard_spec`
--
DROP TRIGGER `hrms`.`timecard_spec_after_upd_tr`;
DELIMITER //
CREATE TRIGGER `hrms`.`timecard_spec_after_upd_tr` AFTER UPDATE ON `hrms`.`timecard_spec`
 FOR EACH ROW BEGIN

     set @emp_no=new.emp_no;

     set @dept_id = new.dept_id;

     set @full_name = new.full_name;

     set @start_date = new.start_date;

     set @total_day = new.total_day;

     set @total_hour = new.total_hour;

     set @total_minute = new.total_minute;

     set @leave_type = new.leave_type;

     set @t_status = new.status;

     set @create_by = new.create_by;

     set @update_by = new.update_by;

     set @forget_times=new.forget_times;



     if (@t_status=9 and @leave_type=21) then

        set @cur_date=DATE_FORMAT(date_add(FROM_UNIXTIME(@start_date),interval -8 hour),'%Y-%m');

        set @total_time =@total_day*480+@total_hour*60+@total_minute;

        if (INSTR(@forget_times,'1,2')=1) then

            set @forget_times=2;

        else

            set @forget_times=1;

        end if;

        if exists(select * from timecard_rpt where cur_date=@cur_date and emp_no =@emp_no) then

            update timecard_rpt set forgot_timecard=forgot_timecard+@forget_times where cur_date=@cur_date and emp_no =@emp_no;

        else

            insert into timecard_rpt (dept_id,emp_no,full_name,cur_date,forgot_timecard,create_by,create_date)

            values (@dept_id,@emp_no,@full_name,@cur_date,@forget_times,@create_by,UNIX_TIMESTAMP(now()));

        end if;

     end if;

END
//
DELIMITER ;

 

 

 

 

 

 

 

DROP TRIGGER `hrms`.`employee_after_upd_tr`;
DELIMITER //
CREATE TRIGGER `hrms`.`employee_after_upd_tr` AFTER UPDATE ON `hrms`.`employee`
 FOR EACH ROW BEGIN

  

   set @my_leader = new.my_leader;

   set @emp_no = new.emp_no;

   set @create_by = new.create_by;

   set @create_date= new.create_date;

   if (exists(select emp_no from hr_relation where emp_no=@emp_no)) then

       update hr_relation set leader_no = @my_leader,create_by=@create_by,create_date=@create_date where emp_no=@emp_no;

   else

     insert into hr_relation (emp_no,leader_no,create_date,create_by) values (@emp_no,@my_leader,@create_date,@create_by);

   end if;

   if (NEW.dept_id != OLD.dept_id) then
       update timecard_rpt set dept_id = NEW.dept_id where emp_no = @emp_no;
   end if;

END
//
DELIMITER ;

 

 

 

 

DROP TRIGGER `hrms`.`holiday_after_ins_tr`;
DELIMITER //
CREATE TRIGGER `hrms`.`holiday_after_ins_tr` AFTER UPDATE ON `hrms`.`holiday`
 FOR EACH ROW BEGIN

     set @emp_no=new.emp_no;

     set @dept_id = new.dept_id;

     set @full_name = new.full_name;

     set @start_date = new.start_date;

     set @total_day = new.total_day;

     set @total_hour = new.total_hour;

     set @total_minute = new.total_minute;

     set @leave_type = new.leave_type;

     set @t_status = new.status;

     set @create_by = new.create_by;

     set @update_by = new.update_by;

    

     set @cur_date=DATE_FORMAT(date_add(FROM_UNIXTIME(@start_date),interval -8 hour),'%Y-%m');

     set @total_time =@total_day*480+@total_hour*60+@total_minute;

     if (@t_status=9) then

       

        if exists(select * from timecard_rpt where cur_date=@cur_date and emp_no =@emp_no) then

             if @leave_type=1 THEN

               update timecard_rpt set leave_1=leave_1+@total_time where cur_date=@cur_date and emp_no =@emp_no;

            elseif @leave_type=2 THEN

               update timecard_rpt set leave_2=leave_2+@total_time where cur_date=@cur_date and emp_no =@emp_no;

            elseif @leave_type=3 THEN

               update timecard_rpt set leave_3=leave_3+@total_time where cur_date=@cur_date and emp_no =@emp_no;

            elseif @leave_type=4 THEN

               update timecard_rpt set leave_4=leave_4+@total_time where cur_date=@cur_date and emp_no =@emp_no;

            elseif @leave_type=5 THEN

               update timecard_rpt set leave_5=leave_5+@total_time where cur_date=@cur_date and emp_no =@emp_no;

            elseif @leave_type=6 THEN

               update timecard_rpt set leave_6=leave_6+@total_time where cur_date=@cur_date and emp_no =@emp_no;

            elseif @leave_type=7 THEN

               update timecard_rpt set leave_7=leave_7+@total_time where cur_date=@cur_date and emp_no =@emp_no;

            elseif @leave_type=8 THEN

               update timecard_rpt set leave_8=leave_8+@total_time where cur_date=@cur_date and emp_no =@emp_no;

            elseif @leave_type=9 THEN

                update timecard_rpt set leave_9=leave_9+@total_time where cur_date=@cur_date and emp_no =@emp_no;

           elseif @leave_type=10 THEN

               update timecard_rpt set leave_10=leave_10+@total_time where cur_date=@cur_date and emp_no =@emp_no;

            end if;

        else

            if @leave_type=1 THEN

               insert into timecard_rpt (dept_id,emp_no,full_name,cur_date,leave_1,create_by,create_date)

               values (@dept_id,@emp_no,@full_name,@cur_date,@total_time,@create_by,UNIX_TIMESTAMP(now()));

            elseif @leave_type=2 THEN

               insert into timecard_rpt (dept_id,emp_no,full_name,cur_date,leave_2,create_by,create_date)

               values (@dept_id,@emp_no,@full_name,@cur_date,@total_time,@create_by,UNIX_TIMESTAMP(now()));

            elseif @leave_type=3 THEN

               insert into timecard_rpt (dept_id,emp_no,full_name,cur_date,leave_3,create_by,create_date)

               values (@dept_id,@emp_no,@full_name,@cur_date,@total_time,@create_by,UNIX_TIMESTAMP(now()));

            elseif @leave_type=4 THEN

               insert into timecard_rpt (dept_id,emp_no,full_name,cur_date,leave_4,create_by,create_date)

               values (@dept_id,@emp_no,@full_name,@cur_date,@total_time,@create_by,UNIX_TIMESTAMP(now()));

            elseif @leave_type=5 THEN

               insert into timecard_rpt (dept_id,emp_no,full_name,cur_date,leave_5,create_by,create_date)

               values (@dept_id,@emp_no,@full_name,@cur_date,@total_time,@create_by,UNIX_TIMESTAMP(now()));

            elseif @leave_type=6 THEN

               insert into timecard_rpt (dept_id,emp_no,full_name,cur_date,leave_6,create_by,create_date)

               values (@dept_id,@emp_no,@full_name,@cur_date,@total_time,@create_by,UNIX_TIMESTAMP(now()));

            elseif @leave_type=7 THEN

               insert into timecard_rpt (dept_id,emp_no,full_name,cur_date,leave_7,create_by,create_date)

               values (@dept_id,@emp_no,@full_name,@cur_date,@total_time,@create_by,UNIX_TIMESTAMP(now()));

            elseif @leave_type=8 THEN

               insert into timecard_rpt (dept_id,emp_no,full_name,cur_date,leave_8,create_by,create_date)

               values (@dept_id,@emp_no,@full_name,@cur_date,@total_time,@create_by,UNIX_TIMESTAMP(now()));

            elseif @leave_type=9 THEN

               insert into timecard_rpt (dept_id,emp_no,full_name,cur_date,leave_9,create_by,create_date)

               values (@dept_id,@emp_no,@full_name,@cur_date,@total_time,@create_by,UNIX_TIMESTAMP(now()));

            elseif @leave_type=10 THEN

               insert into timecard_rpt (dept_id,emp_no,full_name,cur_date,leave_10,create_by,create_date)

               values (@dept_id,@emp_no,@full_name,@cur_date,@total_time,@create_by,UNIX_TIMESTAMP(now()));

            end if;

        end if;

     elseif(@t_status=10) then

             if @leave_type=1 THEN

               update timecard_rpt set leave_1=leave_1-@total_time where cur_date=@cur_date and emp_no =@emp_no;

            elseif @leave_type=2 THEN

               update timecard_rpt set leave_2=leave_2-@total_time where cur_date=@cur_date and emp_no =@emp_no;

            elseif @leave_type=3 THEN

               update timecard_rpt set leave_3=leave_3-@total_time where cur_date=@cur_date and emp_no =@emp_no;

            elseif @leave_type=4 THEN

               update timecard_rpt set leave_4=leave_4-@total_time where cur_date=@cur_date and emp_no =@emp_no;

            elseif @leave_type=5 THEN

               update timecard_rpt set leave_5=leave_5-@total_time where cur_date=@cur_date and emp_no =@emp_no;

            elseif @leave_type=6 THEN

               update timecard_rpt set leave_6=leave_6-@total_time where cur_date=@cur_date and emp_no =@emp_no;

            elseif @leave_type=7 THEN

               update timecard_rpt set leave_7=leave_7-@total_time where cur_date=@cur_date and emp_no =@emp_no;

            elseif @leave_type=8 THEN

               update timecard_rpt set leave_8=leave_8-@total_time where cur_date=@cur_date and emp_no =@emp_no;

            elseif @leave_type=9 THEN

                update timecard_rpt set leave_9=leave_9-@total_time where cur_date=@cur_date and emp_no =@emp_no;

           elseif @leave_type=10 THEN

               update timecard_rpt set leave_10=leave_10-@total_time where cur_date=@cur_date and emp_no =@emp_no;

            end if;

     end if;

END
//
DELIMITER ;

 

 

 

 

DROP TRIGGER `hrms`.`timecard_spec_after_upd_tr`;
DELIMITER //
CREATE TRIGGER `hrms`.`timecard_spec_after_upd_tr` AFTER UPDATE ON `hrms`.`timecard_spec`
 FOR EACH ROW BEGIN

     set @emp_no=new.emp_no;

     set @dept_id = new.dept_id;

     set @full_name = new.full_name;

     set @start_date = new.start_date;

     set @total_day = new.total_day;

     set @total_hour = new.total_hour;

     set @total_minute = new.total_minute;

     set @leave_type = new.leave_type;

     set @t_status = new.status;

     set @create_by = new.create_by;

     set @update_by = new.update_by;

     set @forget_times=new.forget_times;



     if (@t_status=9 and @leave_type=21) then

        set @cur_date=DATE_FORMAT(date_add(FROM_UNIXTIME(@start_date),interval -8 hour),'%Y-%m');

        set @total_time =@total_day*480+@total_hour*60+@total_minute;

        if (INSTR(@forget_times,'1,2')=1) then

            set @forget_times=2;

        else

            set @forget_times=1;

        end if;

        if exists(select * from timecard_rpt where cur_date=@cur_date and emp_no =@emp_no) then

            update timecard_rpt set forgot_timecard=forgot_timecard+@forget_times where cur_date=@cur_date and emp_no =@emp_no;

        else

            insert into timecard_rpt (dept_id,emp_no,full_name,cur_date,forgot_timecard,create_by,create_date)

            values (@dept_id,@emp_no,@full_name,@cur_date,@forget_times,@create_by,UNIX_TIMESTAMP(now()));

        end if;

     end if;

END
//
DELIMITER ;

分享到:
评论

相关推荐

    mysql触发器之创建多个触发器操作实例分析

    本文实例讲述了mysql触发器之创建多个触发器操作。分享给大家供大家参考,具体如下: 这次记录的内容mysql 版本必须得是5.7.2+的哈,之前的会不好使的。废话不多说,咱们开始正文哈。 在mysql 5.7.2+版本之前,我们...

    mysql触发器之触发器的增删改查操作示例

    MySQL触发器是数据库管理系统提供的一种机制,用于在特定的数据操作(如INSERT、UPDATE、DELETE)发生之前或之后自动执行预定义的SQL语句。这些触发器可以用来实现复杂的业务规则,确保数据的一致性和完整性,或者...

    MYSQL触发器教程.doc

    MySQL触发器是数据库管理系统中的一种重要机制,它允许在特定的数据库操作(如INSERT、UPDATE、DELETE)发生前后自动执行一段预定义的SQL代码。触发器的引入是为了满足更复杂的数据完整性需求,提供数据验证、业务...

    mysql触发器+存储过程

    文件“MySQL存储过程.pdf”和“OReilly.MySQL.Stored.Procedure.Programming.rar”可能会提供关于如何创建、调用和管理MySQL存储过程的详细指南,而“MySQL触发器.rar”则可能包含触发器的创建、使用和优化方面的...

    MySQL触发器.pdf

    ### MySQL触发器详解 #### 引言 MySQL触发器,作为MySQL 5.0版本引入的一项重要特性,为数据库管理提供了更为精细的控制能力。触发器允许在特定的数据库操作(如INSERT、UPDATE、DELETE)发生时自动执行SQL语句,...

    MYSQL触发器使用详解

    MYSQL触发器,可以使用它用来进行监控,例如商品价格变化,下单后商品库存减少等实用性操作!

    mysql触发器使用

    在深入探讨MySQL触发器的使用之前,我们先来理解一下什么是触发器以及它在数据库管理中的作用。触发器是数据库中一种特殊的存储过程,当特定的事件(如INSERT、UPDATE或DELETE操作)在指定的表上发生时自动执行。...

    mysql触发器教程

    ### MySQL触发器教程知识点详解 #### 一、MySQL触发器简介 MySQL触发器是一种存储在数据库中的特殊类型的存储过程,当特定的事件(如插入、更新或删除数据)发生时自动执行。它们允许用户定义一系列复杂的规则和...

    mysql触发器文档

    ### MySQL触发器知识点详解 #### 引言 MySQL触发器是一种服务器端的程序,它可以响应特定的数据库事件(如插入、更新或删除记录)而自动执行。触发器自MySQL 5.0版本起被引入,这标志着MySQL在功能性上的一大进步,...

    MySQL触发器.rar

    MySQL触发器是数据库管理系统中的一个重要概念,主要用于在特定的数据操作(如INSERT、UPDATE或DELETE)发生时自动执行预定义的SQL语句。这些语句可以是复杂的业务逻辑,用于实现数据验证、同步或其他自动化任务。...

    mysql触发器之创建使用触发器简单示例

    本文实例讲述了mysql触发器之创建使用触发器。分享给大家供大家参考,具体如下: 我们可以可以使用CREATE TRIGGER语句创建一个新的触发器,来看下具体的语法: CREATE TRIGGER trigger_name trigger_time trigger_...

    MySQL触发器、存储过程、自定义函数、视图示例

    ### MySQL触发器、存储过程、自定义函数、视图示例 #### 一、MySQL触发器 触发器是一种特殊类型的存储过程,它被设计为在特定事件(如INSERT、UPDATE或DELETE操作)发生时自动执行。触发器可以用来强制业务规则、...

    mysql触发器.zip

    MySQL触发器是数据库管理系统中的一个重要特性,它允许在特定的数据库操作(如INSERT、UPDATE或DELETE)发生之前或之后执行自定义的SQL代码。这些自动执行的代码块可以用来实现复杂的业务逻辑,确保数据的一致性和...

    mysql触发器使用实例

    MySQL触发器是数据库管理系统中的一个重要特性,它允许在特定的数据操作(如INSERT、UPDATE或DELETE)发生时自动执行预定义的SQL语句。这为数据库的业务规则提供了强大的支持,可以确保数据的一致性和完整性。以下是...

    mysql触发器.pdf

    【MySQL触发器详解】 MySQL触发器是数据库管理系统中的一种重要特性,它允许用户在特定的数据库操作(如INSERT、UPDATE或DELETE)发生之前或之后自动执行预定义的SQL语句。这种特性使得数据库能实现更复杂的业务...

    MYSQL触发器在PHP项目中用来做信息备份、恢复和清空

    在MySQL数据库中,触发器是一种非常强大的工具,可以在特定的数据操作(如INSERT, UPDATE, DELETE)发生时自动执行预定义的SQL语句。在PHP项目中,我们可以利用触发器来实现信息的备份、恢复和清空功能,以提高数据...

Global site tag (gtag.js) - Google Analytics