1

I have three tables: users, account and accountinfo and I am trying to make a trigger that will add the id from users to the UserID column in the account table. Here is what I tried:

CREATE TRIGGER catchUser BEFORE INSERT ON defaultdatabase.users 
FOR EACH ROW
BEGIN
INSERT INTO defaultdatabase.account(UserID) VALUES (new.id);
END

However, I get an error right after my INSERT statement that says,

Syntax Error: insert 'semicolon'

Why am I getting this error is I have the semicolon or is my trigger just wrong?

I'm using MySQL 5.6 if that makes any difference as well.

0

3 Answers 3

1

You need to specify the delimiter:

delimiter //
CREATE TRIGGER catchUser BEFORE INSERT ON defaultdatabase.users 
FOR EACH ROW
BEGIN
INSERT INTO defaultdatabase.account(UserID) VALUES (new.id);
END; //
delimiter ;
Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

CREATE TRIGGER catchUser BEFORE INSERT ON defaultdatabase.users 
FOR EACH ROW
BEGIN
INSERT INTO defaultdatabase.account(UserID) VALUES (new.id)
END;

Comments

0

Please insert a semicolon after END.

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.