John Hack
John Hack

Reputation: 87

MySQL trigger syntax error

I am just creating a trigger for MySQL. But I am getting the below error.

ERROR 1064 (42000): 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 'END' at line 1

Below is my code to create a trigger.

DROP TRIGGER IF EXISTS user_contact_after_insert;
DELIMITER //
CREATE TRIGGER `user_contact_after_insert`
AFTER INSERT ON `forum_user`
  FOR EACH ROW
  BEGIN
    INSERT INTO `user_contact` (email) VALUES (LCASE(NEW.FIRST_NAME NEW.LAST_NAME+'@gmail.com'));
  END;
DELIMETER ;

Here I have two tables forum_user & user_contact. In forum_user table I have four column like ID, first_name, last_name, Date and in user_contact table I have two columns ID & email.

Now Here I want to create trigger which will insert a row at user_contact table when one row will insert into the forum_user table with the recent value from first_name & last_name.

Am I doing anything wrong in this code. Any help will be appreciable.

Upvotes: 0

Views: 684

Answers (1)

John Woo
John Woo

Reputation: 263723

change the DELIMITER and use CONCAT

DROP TRIGGER IF EXISTS user_contact_after_insert;

DELIMITER // 

CREATE TRIGGER `user_contact_after_insert` 
AFTER INSERT ON `forum_user` 
FOR EACH ROW 
BEGIN 
    INSERT INTO `user_contact` (email) 
    VALUES (LCASE(CONCAT(NEW.FIRST_NAME, NEW.LAST_NAME,'@gmail.com'))); 
END//    --- <<=== HERE

DELIMITER ;

Upvotes: 2

Related Questions