Question

Error code 1064, SQL state 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'BEGIN INSERT INTO mst_gate (gate_id,gate_name,status) VALUES' at line 2

DELIMITER @@  
CREATE TRIGGER vms.ins_gate  
BEGIN  
    INSERT INTO `mst_gate` (`gate_id`,`gate_name`,`status`)   
        VALUES (new.gate_id, new.gate_name, new.status);  
  END @@  
DELIMITER ; 
Was it helpful?

Solution

Wrong trigger syntax,try

    DELIMITER @@  
    CREATE TRIGGER vms.ins_gate  BEFORE INSERT ON sometable
    FOR EACH ROW
    BEGIN  
        INSERT INTO `mst_gate` (`gate_id`,`gate_name`,`status`)   
            VALUES (new.gate_id, new.gate_name, new.status);  
      END @@  
    DELIMITER ; 

OTHER TIPS

You are missing the {BEFORE | AFTER} INSERT ON {TABLE NAME}, and FOR EACH ROW clauses in your SQL.

Your Create trigger should be reading like this:

CREATE TRIGGER vms.ins_gate BEFORE INSERT ON vms.gate

OR

CREATE TRIGGER vms.ins_gate AFTER INSERT ON vms.gate

Possibly:

DELIMITER @@
CREATE TRIGGER vms.ins_gate BEFORE INSERT ON vms.gate
  FOR EACH ROW BEGIN
    INSERT INTO mst_gate (gate_id,gate_name,status)
                VALUES (new.gate_id, new.gate_name, new.status);
  END
@@
DELIMITER ;

Refer to: MySQL: CREATE TRIGGER Syntax

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top