MySQL Syntax Error When Creating a Trigger

errorsMySQLsyntaxtrigger

I am trying to create a trigger but I am getting a syntax error and I am not really sure why I am.

CREATE TRIGGER Section_Insert AFTER INSERT ON Section
    -> FOR EACH ROW BEGIN
    -> INSERT INTO Audit(changeTime, tableName, Action) VALUES (NOW(), 'Section', 'INSERT');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 3

Best Answer

You need to use the Delimiter /// first if you are creating a trigger.

Delimiter ///
CREATE TRIGGER Section_Insert AFTER INSERT ON Section
FOR EACH ROW BEGIN
INSERT INTO Audit(changeTime, tableName, Action) VALUES (NOW(), 'Section', 'INSERT');
End;
///