Kenneth Fisher adds four columns to a table:
One of the easiest ways to collect information about table activity is to add a series of audit columns to the table. The most common set of column consists of four columns.
– When was the row created?
– Who created it?
– When was the row last updated?
– Who last updated it?
Read on to see how to create these, but definitely read the comments. Joe Celko has a good reason to avoid this style, and there’s another good reason as well: if you update the columns and the updated values are longer than what they replace, you can end up generating a lot of page splits as full pages get broken up to handle those in-page updates.
If you do need something like this, I’m growing more and more fond of an activity log table which is append-only and tracks these operations separately. That removes the page splits, allows you to deal with deletions, and gives a better idea of what happened over time for a third party. It does come at a cost if you frequently need to show the create and last updated dates (or users), but my experience has been that a vast majority of the time, we include those for internal purposes, not to display to users.
Comments closed