首页 > 数据库 > mysql教程 > MySQL 5.1触发器小试

MySQL 5.1触发器小试

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
发布: 2016-06-07 16:55:23
原创
996 人浏览过

我一直以为MySQL 5.0的触发器好似没那么强大,被一个搞mssql的老大给忽悠了,其实MySQL触发器从5.0就变得很强大,当然包括5.1。这

我一直以为MySQL 5.0的触发器好似没那么强大,被一个搞mssql的老大给忽悠了,其实MySQL触发器从5.0就变得很强大,当然包括5.1。

这里拿一个demo说事:

DROP TRIGGER IF EXISTS `ucenterhome`.`uchome_doing_test`;
DELIMITER //
CREATE TRIGGER `ucenterhome`.`uchome_doing_test` AFTER INSERT ON `ucenterhome`.`uchome_doing`
 FOR EACH ROW BEGIN
    INSERT INTO uchome_doing_1 SET doid= NEW.doid+3, uid= NEW.uid , username= NEW.username,`from`=NEW.`from`,dateline=NEW.dateline,message=NEW.message,ip=NEW.ip,replynum = NEW.replynum,mood=NEW.mood;   
END
//
DELIMITER ;

每向uchome_doing表中插一条数据,,就复制到uchome_dong_1表中一条。

有两个关键字:

OLD  NEW

官方的解释:

The OLD and NEW keywords enable you to access columns in the rows affected by a trigger. (OLD and NEW are not case sensitive.) In an INSERT trigger, only NEW.col_name can be used; there is no old row. In a DELETE trigger, only OLD.col_name can be used; there is no new row. In an UPDATE trigger, you can use OLD.col_name to refer to the columns of a row before it is updated and NEW.col_name to refer to the columns of the row after it is updated.

还有两个关键字

BEFORE AFTER

官方解释

The keyword BEFORE indicates the trigger action time. In this case, the trigger should activate before each row inserted into the table. The other allowable keyword here is AFTER.

linux

相关标签:
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
mysql 升级后无法重启mysql服务的问题
来自于 1970-01-01 08:00:00
0
0
0
linux安装mysql报错
来自于 1970-01-01 08:00:00
0
0
0
MySQL停止进程
来自于 1970-01-01 08:00:00
0
0
0
phpstudy不能启动mysql?
来自于 1970-01-01 08:00:00
0
0
0
mysql主主同步,从库不同步应该怎么解决?
来自于 1970-01-01 08:00:00
0
0
0
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板