0

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.

1 Answer 1

2

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 ;
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.