views:

208

answers:

1

I have a table that looks like this

user_id   |  name   |  created_on   |   updated_on
--------------------------------------------------
1         | Peter D | 1/1/2009      |

If I insert or update a record, I'd like a trigger to update the updated_on field with datetime('now'). But I can't find the function name to target the most recently updated row in sqlite3. Is there one?

+1  A: 
CREATE TRIGGER your_table_trig AFTER UPDATE ON your_table
 BEGIN
  update your_table SET updated_on = datetime('now') WHERE user_id = NEW.user_id;
 END;
Doug Currie
Worked like a charm! Thanks.
lightly_recruited
If this answered your question it is customary on SO to "Accept" the answer by clicking on the checkmark next to the answer.
Jim Garrison