Mysql table sync or trigger?
What is the best way to do this with mysql:
I have two tables in the same database (table: Gene and Gcur table).
In the Gene table, I have a last_updated column. In the Gcur table, I have a last_modified column.
I would like to sync the last_modified column with the last_updated column.
For example, I did an update to the last_modified column (from the Gcur table) and the last_updated column (from the Gene table) is automatically updated. The two tables are linked by an identification key.
Should this be possible with triggers? Idea?
Thank!
+2
Fabien barbier
source
to share
1 answer
Yes, it is possible with triggers and is pretty trivial. The result will 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;
+4
Josh davis
source
to share