ITPub博客

首页 > 数据库 > MySQL > mysql触发器

mysql触发器

原创 MySQL 作者:oraclesuperman 时间:2015-07-20 10:23:05 0 删除 编辑

t1前面不能保护into子句:

CREATE TRIGGER t_up
   BEFORE INSERT
   ON t
   FOR EACH ROW
BEGIN
   INSERT  t1(name) values ('insert');
   end;


mysql> show TRIGGERs;
+---------+--------+-------+--------------------------------------------------------+--------+---------+--------------------------------------------+---------+----------------------+----------------------+--------------------+
| Trigger | Event  | Table | Statement                                              | Timing | Created | sql_mode                                   | Definer | character_set_client | collation_connection | Database Collation |
+---------+--------+-------+--------------------------------------------------------+--------+---------+--------------------------------------------+---------+----------------------+----------------------+--------------------+
| t_up    | INSERT | t     | BEGIN
   INSERT  t1(name) values ('insert');
   end | BEFORE | NULL    | STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION | root@%  | utf8                 | utf8_general_ci      | utf8_general_ci    |
+---------+--------+-------+--------------------------------------------------------+--------+---------+--------------------------------------------+---------+----------------------+----------------------+--------------------+
1 row in set (0.00 sec)


mysql> insert into t values ('bcc');
Query OK, 1 row affected (0.02 sec)

mysql> select * from t1;
+--------+
| name   |
+--------+
| insert |
+--------+
1 row in set (0.00 sec)

mysql> update t set name='cccc';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0

mysql> select * from t1;
+--------+
| name   |
+--------+
| insert |
+--------+
1 row in set (0.00 sec)

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29313086/viewspace-1741463/,如需转载,请注明出处,否则将追究法律责任。

上一篇: mysql定时任务
请登录后发表评论 登录
全部评论

注册时间:2015-03-20

  • 博文量
    178
  • 访问量
    398990