How to automatically update a timestamp when rows in other other linked tables are updated
I have a timestamp which updates when the row is updated in my main table. Many tables are linked to it via the ID Primary key. But I want this time stamp automatically updated whenever the other connecting 开发者_JS百科rows from other tables too get updated. How do i do this? Any sort of insert/delete/update should do this for me.
Eg.
Main - Table : ID 4
Sub table 1: ID (Foreign key) 4's row changes data., then it should update ID 4 row in the main table.Similar for Subtable 1 to n
Sounds to me like a trigger on the child tables should be suitable for the job; when a row is updated get the forign key of the updated/inserted/deleted row then update the timestamp of the corresponding row in the main table.
I don't know MySQL so can't give you the exact syntax, but a reference can be found at http://dev.mysql.com/doc/refman/5.0/en/triggers.html
精彩评论