Does the keyword NEW have the per-connection basis aspect to it?

Posted on

Question :

I am watching a mysql table with an after insert trigger and i have started to receive many inserts.I am using NEW.message to get the last inserted message.

Since i am receiving many inserts from many clients,i am thinking there could be a time that two records are inserted concurrently.I know that the OLD and NEW keywords enable you me access columns in the rows affected by a trigger,but does NEW have per-connection uniqueness just like LAST_INSERT_ID()?.

Answer :

A trigger is fired by a SQL statement that makes changes to data in the table for which it is defined. It is important to note that triggers are executed for each row of data affected, not for each statement executed. Therefore the scope of new is actually more limited than session variables (which are connection-specific). The new and old aliases exist only within the local scope of the trigger, so concurrency should not be an issue as long as it is handled correctly in any stored programs which cause a trigger to fire.

Leave a Reply

Your email address will not be published. Required fields are marked *