0
I have 4 table in my Mysql database. -> companies -> contacts (company addresses) -> bank data (company’s bank data) -> members (members of the company )
All tables relate to the companies table. In the companies table I have an updated_at field, which I would like when updated any of the other 3 tables, this field was updated. I thought of a TRIGGER, but I don’t know how to do it.
Really that’s what I need, but it updates the updated_at of all companies... I tried to put something like: UPDATE companies SET updated_at = NOW() WHERE empresa_id = contacts.empresa_id ... but it didn’t work
– Fernando Herique Rubim Pioli
Hmmmm. I didn’t know you have more than one company. Good. What’s in the partners table that defines the company?
– Reginaldo Rigo
i have a company column referencing company
– Fernando Herique Rubim Pioli
And in the table companies which is the column that distinguishes companies?
– Reginaldo Rigo
also calls empresa_id
– Fernando Herique Rubim Pioli
I changed the answer.
– Reginaldo Rigo
Ball show. But I didn’t understand how the new.empresa_id refers to the partners' table empresa_id. could explain me?
– Fernando Herique Rubim Pioli
new.company is the value that is coming to Trigger is Trigger’s way of telling you what is new value of the empresa_id field since we are at the event AFTER THE UPDATE. Follow the logic and create two more for the other tables and you’re done.
– Reginaldo Rigo