Reputation: 3657
I have two tables with the following column names.
users
ui | email | pass
user_profiles
_email | qty | lvl
I am attempting to make sure that everytime a new user is added to the users table that the user_profiles table creates a new row for the new user. However it fails. After reading through many sample trigger statements I can't seem to find the error.
CREATE TRIGGER updatUserProfilesTBL AFTER INSERT ON users
BEGIN
INSERT INTO user_profiles (_email)
VALUES (new.email)
END;
Upvotes: 1
Views: 48
Reputation: 270609
Looks like you are missing the FOR EACH ROW
. Additionally, you will need to alter the DELIMITER
if executing this through the MySQL command line and add a ;
after the insert statement.
DELIMITER $$
CREATE TRIGGER updatUserProfilesTBL AFTER INSERT ON users
FOR EACH ROW BEGIN
INSERT INTO user_profiles (_email)
VALUES (new.email);
END$$
DELIMITER ;
According to the CREATE TRIGGER
spec, it is not optional.
Upvotes: 1