views:

358

answers:

1

What is the best way to do this with mysql :

I have two tables in the same database (a table : Gene, and a table Gcur).

In table Gene, I have a column last_updated. In table Gcur, I have a column last_modified.

I'd like to synchronize column last_modified with column last_updated.

For example, I made an update of column last_modified (from table Gcur), and automatically column last_updated (from table Gene) is updated. Two tables are linked by an ID key.

It should be possible with triggers ? An idea ?

Thanks !

+1  A: 

Yes, it is possible with triggers, and fairly trivial. The result would look like

CREATE TRIGGER au_Gcur AFTER UPDATE ON Gcur
FOR EACH ROW
UPDATE Gene SET last_updated = NEW.last_modified WHERE id = NEW.id;
Josh Davis
Thank you, that's exactly what I'm looking for.
Fabien Barbier