CREATE TRIGGER `db_name`.`trigger_name` BEFORE DELETE ON `db_name`.`table1_name`
FOR EACH ROW
BEGIN
INSERT INTO `db_name`.`table2_name`(table2_id,`comment`,record_created_date)
VALUES (OLD.id, OLD.`comment`, NOW());
END
The syntax error happens at "OLD.comment" because comment is a reserved word in MySql and it's after OLD, the query above doesn't work even with backtick ("`").
Of course, the easiest solution is to change the column name. But, it's not an option in my case. Please help if you know the correct syntax. Thanks.
Line 5 is the line which contains first semicolon in your code. You forget about DELIMITER reassign.
So
But your trigger consists from only one statement, so remove both BEGIN and END lines. DELIMITER reassign not needed in this case.
PS. Use autoutilizing (
DEFAULT CURRENT_TIMESTAMP) fordb_name.table2_name.record_created_datecolumn, and you may skip it away fromINSERT.