Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql how to get the last inserted row values in a trigger

I am writing a trigger after insert event on a table. This is the table

    CREATE TABLE `orderitem` (
       `orderItemId` INT(11) NOT NULL AUTO_INCREMENT,
       `orderItemQuantity` INT(11) NULL DEFAULT NULL,
       `stockId` INT(11) NULL DEFAULT NULL,
       `rate` DOUBLE NULL DEFAULT NULL,
       `orderId` INT(11) NULL DEFAULT NULL,
       PRIMARY KEY (`orderItemId`)
    )

Inside the trigger I need the values inserted for the current row(not only the id) inside the trigger. In T-SQL we can use the inserted table but in MySQL I could not find anything like that. How can I get those values? Thanks in advance.

like image 759
LIH Avatar asked Sep 11 '14 15:09

LIH


1 Answers

You could use OLD. or NEW. since this trigger is fired after the insert both values are the same. You can access all properties of the interred row (if it is a row level trigger) by using:

NEW.orderItemID
NEW.rate

etc.

like image 183
Empty Avatar answered Sep 23 '22 00:09

Empty