I want to update a field with the current timestamp whenever the row is updated.
In MySQL I would do, when declaring the table
LastUpdate TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP
But the "on update" part does not work with SQLite. I could not find a way to do it automatically, do I need to declare a trigger?
EDIT: For the record, here is my current trigger:
CREATE TRIGGER [UpdateLastTime]
AFTER UPDATE
ON Package
FOR EACH ROW
BEGIN
UPDATE Package SET LastUpdate = CURRENT_TIMESTAMP WHERE ActionId = old.ActionId;
END
Thanks
ActionId
andold.ActionId
come from,ActionId
is a column in Jonas' Package table, andold
is defined by SQLite as a reference to the updated rows. (See: sqlite.org/lang_createtrigger.html)UPDATE OF
for all columns but the one holding the date. Ther will be no recursion and the sytnax is simple. See sqlite-triggers