Wednesday, January 10, 2018

How can update table's column in a trigger after update on the same table? [SOLVED]

I have done the solution for same table trigger execute , If you change your trigger to BEFORE instead of AFTER you could do it like this:

---------------------------Create Trigger sdbi_csci_products update time-------------------------------------

DELIMITER //
DROP TRIGGER IF EXISTS update_index_date_csci_products//

CREATE DEFINER=root@localhost TRIGGER update_index_date_csci_products
    BEFORE UPDATE ON `sdbi_csci_products`
    FOR EACH ROW
BEGIN

SET NEW.indexdate=NOW();

END//

DELIMITER ;

-------------------------------------Create Trigger sdbi_csci_products insert time-------------------------

DELIMITER //
DROP TRIGGER IF EXISTS insert_index_date_csci_products//

CREATE DEFINER=root@localhost TRIGGER insert_index_date_csci_products
    BEFORE INSERT ON `sdbi_csci_products`
    FOR EACH ROW
BEGIN

SET NEW.indexdate=NOW();

END//

DELIMITER ;

No comments:

Post a Comment