开发者

Overkill to add last_modified column to all tables?

开发者 https://www.devze.com 2022-12-08 23:41 出处:网络
When designing database tables for a fresh new project, is it good practice to add a last_modified column, which auto-updates, for every table?

When designing database tables for a fresh new project, is it good practice to add a last_modified column, which auto-updates, for every table?

Is the performance hit to have auto-updating last_modified columns too much to make it worthwhile?

This column could have a number o开发者_如何学JAVAf uses, one being to aid with caching. But is it overkill to just throw such a column into every table?

Also - are there other useful reasons to have a last_modified column?

This is specific to MySQL, as it's the only system I use.


It depends!

Do you need to know the last_modified date for each table? If so, then you need that column.

Cater for the domain, and then worry about performance, UNLESS you know that you will have an insane number of INSERTS/UPDATES on that table...


I have found this to be a particularly troubling piece of information. I only get when the record was modified, but not what was modified, or by who or why, or how.

I prefer to have audit tables for my important tables.


Why do you want it?

It will be a small performance hit on insert or update. It is useful on occasion if you need to send out information on records changed since a certain date (what we generally call a delta feed). It is not terribly useful for management of the data changes. Like Raj More, I prefer the audit table approach that stores the data of the change, the old and new value and who made the change. This can then be used to rollback a specifc change or group of changes which is pretty hard to do if you are relying only on backups to rollback bad data.

It is generally not useful at all in cases where the data is static or where it is renewed from a batch process (like an import) rather than the user interface. Why bother to have such a thing on lookup tables for instance?


Well, I would say you should have that column for tables in which records are frequently changed by some user action. And on top of that, if you have authentication in place, it's useful to stored who made the changes. It may also save you some grief when someone goes to you asking who made some changes to a record because something is broken.

0

精彩评论

暂无评论...
验证码 换一张
取 消