-->

Does sqlite3 support a trigger to automatically up

2019-03-18 14:29发布

问题:

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:

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;