>데이터 베이스 >MySQL 튜토리얼 >MySQL 5.1触发器小试

MySQL 5.1触发器小试

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB원래의
2016-06-07 16:55:23987검색

我一直以为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으로 문의하세요.