Possible Duplicate:
mysql getting last_insert_id() in a trigger
I have MySQL TRIGGER
firing AFTER INSERT ON
a table (my_table
).
I wish to store the PRIMARY_KEY
of the row effected by the TRIGGER
in a variable using:
SET @user_id = LAST_INSERT_ID();
Which is backed by this stackoverflow link. And seems to be working.
However, each time it stores the value as 0
.
From this stackoverflow link, I believe this is due to the fact that my_table
is set to AUTO_INCREMENT
.
SET @user_id = LAST_INSERT_ID();
What is the best practice to overcome this?