2016-08-03 8 views
1

ich zwei Tabellen mit den folgenden Feldern gemacht hatte:wie Trigger mit mehreren Zustand in mysql schreiben

TABLE 1: "demo" 
FIELD: "demoid" 
FIELD: "cpid" 
FIELD: "status"  


TABLE 2: "sample" 
FIELD: "id" 
FIELD: "conid"  
FIELD: "statussample" 
FIELD: "date" 

ich die status, wenn die Probe Tabellenfeld aktualisieren möchten statussample geändert wird. Die Bedingung wäre

1) `demoid` and `id` would be same and `cpid` and `conid` would be same.(if more than one values comes i want the last inserted value of `sample` using the field `date`) 

Wie das zu tun? Ich hatte mit this..new stecken Format Trigger

Antwort

1
DELIMITER // 

CREATE TRIGGER sample_after_update 
AFTER UPDATE 
    ON sample FOR EACH ROW 

BEGIN 

    UPDATE demo 
    SET demoid = NEW.id, 
     cpid = NEW.conid 

END; // 
DELIMITER;