我想在mysql的子查询中访问后插入触发器的new
变量。如何从子查询中访问它?
答案 0 :(得分:0)
查看此文章MYSQL: AFTER INSERT TRIGGER
从该链接:
以及如何从该链接访问NEW
,他们的示例是
DELIMITER //
CREATE TRIGGER contacts_after_insert
AFTER INSERT
ON contacts FOR EACH ROW
BEGIN
DECLARE vUser varchar(50);
-- Find username of person performing the INSERT into table
SELECT USER() INTO vUser;
-- Insert record into audit table
INSERT INTO contacts_audit
( contact_id,
deleted_date,
deleted_by)
VALUES
( NEW.contact_id,
SYSDATE(),
vUser );
END; //
DELIMITER ;