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
asked Jul 27, 2014 at 19:11
-
You need a delimiter and you are missing ENDMihai– Mihai2014年07月27日 19:16:39 +00:00Commented Jul 27, 2014 at 19:16
2 Answers 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;
///
answered Jul 28, 2014 at 4:56
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');
answered Oct 27, 2014 at 18:52
lang-sql