session in triggers
hello ' if i create a triggers in mysql now i want to update a table a field when data insertion in table b occurs...then how can i do this for that specific user as i want to know how can i use session_id in triggers or if there is any other开发者_高级运维 way to do this.'
thanks
The following trigger will insert a row into table_b for each insert that takes place in table b.
The newly inserted fields of table_a are accessed by the alias new
.
CREATE
TRIGGER ai_tableb_each AFTER INSERT
ON table_b FOR EACH ROW
BEGIN
DECLARE vUser_id varchar(255);
DECLARE vConnection_id integer;
SET vUser_id = current_user();
SET vConnection_id = connection_id();
INSERT INTO table_b
(field_a, f_user, f_connection)
VALUES (
new.field_a
, vUser_id
, vConnection_id
);
END
Note that the declared variables are not really needed, but you may want to do some action depending on the user or connection id.
精彩评论