Another form of auditing frequently used is to log information in fields in the same row as the data. As an example, let's define a trigger which logs the time and active user in fields
last_changed_by fields at each
UPDATE. In row-level
BEFORE triggers you can modify what actually gets written by changing the
NEW record. You can either assign values to some fields or even return a different record with the same structure. For example, if you return
OLD from the
UPDATE trigger, you effectively make sure that the row can't be updated.
To form the basis of our audit logging in the table, we start with creating a trigger that sets the user who made the last change and when ...