I am trying to create a trigger to write logs when rows in x table have been edited.
This is the current query..
CREATE TRIGGER users_update_trigger
AFTER UPDATE ON users FOR EACH ROW
BEGIN
INSERT INTO users_backlog
(user_id, description, datetime) VALUES (user_id,
CONCAT('modified from ', OLD.value, ' to ', NEW.value), CURTIMESTAMP());
END
The console returns the following error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 6
Can anyone tell me what I'm doing wrong here?
Edit: Schema for relevant tables Users:
CREATE TABLE IF NOT EXISTS `users` (
`user_id` int(11) NOT NULL AUTO_INCREMENT,
`hourly` decimal(10,2) DEFAULT NULL,
`date_paid` date DEFAULT NULL
;
Users_backlog:
CREATE TABLE IF NOT EXISTS `users_backlog` (
`log_id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`description` varchar(50) NOT NULL,
`datetime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
);
OLD.valueandNEW.valuecame from? I can see that you haven't declare those. 2nd is theCURTIMESTAMP()will return aTIMESTAMPnot aDATETIME.userstablepaymentsorusers? auto_incrementuser_idcolumn forpaymentstable doesn't make much sense