0

I have a signup_table with the following columns: Firs name, Surname, Mobile Number, Email Address, Password and Confirm Password.

I am trying to create a trigger through which I can check if the data in the confirm password field is same as that of the password field. Can anyone please let me know how to create a trigger for the same?

Here is what I am doing:

CREATE TRIGGER confirm_password_trigger 
BEFORE INSERT ON `signup_table` 
FOR EACH ROW
BEGIN
IF NEW.confirm_password != New.password THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Password does not match';
END IF;
END
Deep
  • 81
  • 2
  • 11
  • Do you know why trigger is used? – Mayank Pandeyz Apr 17 '17 at 11:47
  • In MySql workbench, we don't have the option to implement constraints. So, in order to implement constraints we can use triggers. Correct me if am wrong. – Deep Apr 17 '17 at 11:57
  • That's not the use of triggers, get your fact corrected and then you cannot use triggers for this – Mayank Pandeyz Apr 17 '17 at 12:06
  • Check this http://stackoverflow.com/questions/39055586/mysql-workbench-check-constraint. As per Gordon Linoff: MySQL doesn't enforce check constraints. If we need checks then we can use Triggers in MySQL. – Deep Apr 17 '17 at 12:09
  • What do think is wrong with the code you have published? – P.Salmon Apr 17 '17 at 13:08
  • I was not sure if it is going to work or not as I am using MySql workbench for the first time and it worked.. :) Though thanks for your time...!!! – Deep Apr 17 '17 at 15:54

0 Answers0