Creating an SQL Trigger (using SQLyog) Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Creating an SQL Trigger (using SQLyog) without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I’m having a hard time trying to make a trigger. i can find a lot of examples that show how to make triggers, but nothing that helps with my specific issue. I need to make a trigger in my exam project and I want it to take the entered email and make it lowercase. Should be quite simple – but i’m not able to do it. So now i’m asking for help.

This is what i got from the sql program, and it should be easy to just insert the right values.

    DELIMITER $$
 CREATE
/*[DEFINER = { user | CURRENT_USER }]*/
TRIGGER `awesomegame`.`lowercase` AFTER INSERT
ON `awesomegame`.`users`
FOR EACH ROW BEGIN
UPDATE LOWER(sEmail);
END$$ DELIMITER ;

What do i do?

Answer

Use BEFORE INSERT instead of AFTER INSERT, and use the new keyword to access and modify the sEmail field.

CREATE TRIGGER `awesomegame`.`lowercase` BEFORE INSERT ON `awesomegame`.`users` FOR EACH ROW
SET NEW.sEmail = LOWER(NEW.sEmail);

You can (should ?) do the same thing for BEFORE UPDATE.

We are here to answer your question about Creating an SQL Trigger (using SQLyog) - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji