插入触发器后如何创建更新

时间:2019-04-11 01:45:37

标签: mysql triggers

您好,我想在插入表后创建一个触发器,此触发器的目的是更新同一表上的一行,这是我编写的代码,我使用phpmyadmin

 UPDATE commande SET NEW.CodeLivreurClient= SHA1(concat(NEW.IdCommande,"_",NEW.DateCommande,"_",NEW.HoraireCommande,"_",NEW.IdClient))

下表如下:

  CREATE TABLE `commande` (
     `IdCommande` int(11) NOT NULL,
     `DateCommande` date NOT NULL,
     `HoraireCommande` time NOT NULL,
     `MethodePaiement` varchar(256) NOT NULL,
     `StatusPaiement` tinyint(1) NOT NULL,
     `StatusCommande` varchar(256) NOT NULL,
     `CodeLivreurRestaurant` varchar(6) DEFAULT NULL,
     `CodeLivreurClient` varchar(6) DEFAULT NULL,
     `IdLivreur` int(11) NOT NULL,
     `IdClient` int(11) NOT NULL
   )

触发器是:

CREATE DEFINER=root@localhost TRIGGER Apres_Insert_Commande
    AFTER INSERT ON commande
    FOR EACH ROW
UPDATE commande
    SET NEW.CodeLivreurClien t= SHA1(concat(NEW.IdCommande,"", NEW.DateCommande,"", NEW.HoraireCommande, "_", NEW.IdClient)); 

0 个答案:

没有答案