An attempt to execute the first trigger, which should insert the value of one table into another only if the data is new. Below is my code:
BEGIN DECLARE email VARCHAR(30); INSERT INTO data_audit SET data_audit_id = OLD.id; IF (NEW.email = OLD.email) THEN email = NULL; ELSE email = OLD.email; END IF; UPDATE corporate_audit SET email = email WHERE corporate_audit_id = last_insert_id(); END
I get the following error:
You have an error in the SQL syntax; check the manual that matches your version of MySQL server for the correct syntax to use near '= NULL; ELSE email = OLD.email; END IF; UPDATE Corporate_audit SET 'on line 5
And when I execute the code without the IF-THEN block and save the OLD.email, it just inserts the new identifier into the audit table, but does not update the field. Please guide me
source share