我一直以为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
官方的解释:
发卡宝是一个专业的软件卡密等虚拟商品在线交易平台,拥有多种兑换方式,费率低,结算快,正规企业平台一直稳定运营,24小时不间断提供自动发卡服务。【模板说明】试用版自带一套模板(响应式)【环境支持】PHP环境 / 200M或以上空间大小 / 开启父路径 / 设置index.php为默认首页 / 目录写入权限需要开启【数据库】MySQL【安装步骤】将文件上传至空间目录,运行“http://域名/inst
1
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.

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号