0

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
  • You need a delimiter and you are missing END – Mihai Jul 27 '14 at 19:16
2

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;
///
1

Since the Trigger has a single line, you don't need a delimiter and you do not need BEGIN END

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.