MySQL 触发数据复制
MySQL triggers data copy
我有一个如下所示的触发器:
delimiter //
create trigger tracker after insert on Items for each row
begin
end; //
delimiter ;
我需要将插入列的 id
、type
和 date_created
插入到另一个 table 作为
INSERT INTO Tracker (table_id, type, date) VALUES ( ??? );
我不确定如何在触发器中获取这些数据字段。有人可以给我提示吗
您可以使用 NEW.column_name
在触发器中获取插入的值
INSERT INTO Tracker (table_id, type, date)
VALUES ( NEW.id_col_traker,NEW.col,NEW.col );
Within the trigger body, the OLD and NEW keywords enable you to access
columns in the rows affected by a trigger. OLD and NEW are MySQL
extensions to triggers; they are not case sensitive.
使用
中显示的新别名
MySQL trigger On Insert/Update events
举个例子
在帐户上插入之前创建触发器 ins_sum
对于每行设置 @sum = @sum + NEW.amount;
我有一个如下所示的触发器:
delimiter //
create trigger tracker after insert on Items for each row
begin
end; //
delimiter ;
我需要将插入列的 id
、type
和 date_created
插入到另一个 table 作为
INSERT INTO Tracker (table_id, type, date) VALUES ( ??? );
我不确定如何在触发器中获取这些数据字段。有人可以给我提示吗
您可以使用 NEW.column_name
在触发器中获取插入的值
INSERT INTO Tracker (table_id, type, date)
VALUES ( NEW.id_col_traker,NEW.col,NEW.col );
Within the trigger body, the OLD and NEW keywords enable you to access columns in the rows affected by a trigger. OLD and NEW are MySQL extensions to triggers; they are not case sensitive.
使用
中显示的新别名MySQL trigger On Insert/Update events
举个例子 在帐户上插入之前创建触发器 ins_sum 对于每行设置 @sum = @sum + NEW.amount;