Help to insert data into the table

Asked

Viewed 27 times

-1

I have a table on Mysql with the name usuários with the following items: convite,quantidade_de_convites. I want when adding an invitation, update the amount how I do it?.

1 answer

0

If you want to update the user table after inserting a record in the invitation table, you can use a TRIGGER. Here’s an example:

DELIMITER $$
CREATE TRIGGER update_convite AFTER INSERT ON convite
FOR EACH ROW BEGIN
UPDATE usuarios SET quantidade_de_convites = quantidade_de_convites + 1 WHERE USUARIO_ID = NEW.USUARIO_iD;
END $$
DELIMITER ;

In the case of this example, the user table would receive a field called user_id, it would be the key to update the user table

Here is a tutorial explaining how triggers work

https://www.devmedia.com.br/mysql-basico-triggers/37462

  • need to do something before creating the Trigger? here is giving table error

Browser other questions tagged

You are not signed in. Login or sign up in order to post.