Reputation: 83
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.
Upvotes: 1
Views: 52
Reputation: 312289
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 ;
Upvotes: 1
Reputation: 4501
Try this:
CREATE TRIGGER catchUser BEFORE INSERT ON defaultdatabase.users
FOR EACH ROW
BEGIN
INSERT INTO defaultdatabase.account(UserID) VALUES (new.id)
END;
Upvotes: 0