Mysql how to get last inserted row values ​​in trigger

I am writing a trigger after insert event on a table. This is a 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 just the ID) inside the trigger. In T-SQL we can use the inserted table, but in MySQL I couldn't find anything like it. How can I get these values? Thanks in advance.

+3


source to share


2 answers


You can use OLD. or NEW. since this trigger fires after insertion, both values ​​are the same. You can access all the properties of an interpolar string (if it is a row level trigger) using:

NEW.orderItemID
NEW.rate

      



and etc.

+5


source


In MySQL, you are using keyworkd NEW instead of Inserted. http://dev.mysql.com/doc/refman/5.0/en/trigger-syntax.html



0


source







All Articles