我正在尝试创建一个触发器,但我收到语法错误,我不确定为什么会这样。
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
答案 0 :(得分:0)
以下内容可能有用:
DELIMITER //
DROP TRIGGER IF EXISTS `Section_Insert`//
DROP TABLE IF EXISTS `Section`//
CREATE TABLE `Section` (
`changeTime` DATETIME NOT NULL,
`tableName` VARCHAR(64) NOT NULL,
`Action` VARCHAR(64) NOT NULL
)//
CREATE TRIGGER `Section_Insert` AFTER INSERT ON `Section`
FOR EACH ROW
BEGIN
INSERT INTO `Audit`(`changeTime`, `tableName`, `Action`) VALUES (NOW(), 'Section', 'INSERT');
END//
DELIMITER ;