I do not know how to do this without having two additional columns in the table, but I do this to update them, to make it run the database, not the application logic.
There are some advantages, but also some disadvantages to using the trigger approach.
First, the benefits:
- It is much easier to add it so that an afterthought to the application. Very few changes to the application / site code. The trigger will take care of all this. (assuming you insert new lines by specifying field names)
- Triggers will take care of any other ways of changing data - someone will change the line from the console, it will still trigger the trigger, like another application that uses the same database.
- Allows the possibility (although I do not) to have a clean row, inserted / updated table.
But some cons too:
- If you donβt know that triggers make these updates, you can often overlook it and the triggers are forgotten when you switch to another server, etc.
source share