创建和修改是每个数据库表都应该有的两个字段吗?

发布于 2024-09-17 12:24:50 字数 173 浏览 4 评论 0原文

我最近意识到我向我的大多数表添加了某种形式的行创建时间戳和可能的“更新日期”字段。突然我开始思考,也许数据库中的每个表都应该有一个在幕后模型中设置的createdmodified字段。

这听起来正确吗?是否有任何类型的高负载表(如会话)或大型表这不是一个好主意?

I recently realized that I add some form of row creation timestamp and possibly a "updated on" field to most of my tables. Suddenly I started thinking that perhaps every table in the database should have a created and modified field that are set in the model behind the scenes.

Does this sound correct? Are there any types of high-load tables (like sessions) or massive sized tables that this wouldn't be a good idea for?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

憧憬巴黎街头的黎明 2024-09-24 12:24:50

我不会将这些字段(我通常称为审核字段)放在每个数据库表上。如果它是一个低流量、高价值的表(例如Users),那么毫无疑问它会继续下去。我还会添加creatormodifier。如果它是一个经常被访问的表(例如操作历史表),那么可能带来的好处不值得增加插入时间和存储空间的成本。

您需要为每张桌子单独进行此调用。

I wouldn't put those fields (which I generally call audit fields) on every database table. If it's a low-traffic, high-value table (like Users, for instance), it goes on, no question. I'd also add creator and modifier. If it's a table that gets hit a lot (an operation history table, say), then maybe the benefit isn't worth the cost of increased insert time and storage space.

It's a call you'll need to make separately for each table.

瀞厅☆埖开 2024-09-24 12:24:50

显然,没有单一的规则。

我的大多数表都有与日期相关的内容,DateCreated、DateModified,偶尔还有 Revision 来跟踪更改等。做任何有意义的事情。显然,您可以发明适当的情况和不适当的情况。如果您询问是否应该“默认”将它们添加到大多数表中,我会说“可能”。

Obviously, there isn't a single rule.

Most of my tables have date-related things, DateCreated, DateModified, and occasionally a Revision to track changes and so on. Do whatever makes sense. Clearly, you can invent cases where it's appropriate and cases where it is not. If you're asking whether you should add them "by default" to most tables, I'd say "probably".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文