0

My trigger query:

CREATE DEFINER = CURRENT_USER TRIGGER `test`.`users_AFTER_INSERT` AFTER INSERT ON `users` FOR EACH ROW
BEGIN
 UPDATE test.users
 SET enabled=1
    FROM Inserted i
    WHERE username = i.username
END

It complains about this part: SET enabled=1. I have tried adding quotes, didn't help.

Most likely the syntax is wrong, but I can't figure out what exactly is wrong here.

EDIT:

Or could it be done like this?

CREATE DEFINER = CURRENT_USER TRIGGER `test`.`users_AFTER_INSERT` AFTER INSERT ON `users` FOR EACH ROW
BEGIN
 UPDATE test.users
 SET enabled=1
 WHERE username = NEW.username;
END
2
  • Where is alias i defined? (i.username) Commented Feb 21, 2016 at 10:12
  • I thought Inserted would be enough, just like NEW, now I have doubts. Could I use NEW instead? Commented Feb 21, 2016 at 10:14

1 Answer 1

1

remove from inserted query:

delimiter | 
CREATE DEFINER = CURRENT_USER TRIGGER `test`.`users_AFTER_INSERT` AFTER INSERT ON `users` FOR EACH ROW
BEGIN
 UPDATE test.users
 SET enabled=1
    WHERE username = i.username;
END
| 
delimiter ;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.