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
1
  • You need a delimiter and you are missing END Commented Jul 27, 2014 at 19:16

2 Answers 2

3

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

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');

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.