数据库日期字段 - 命名约定
命名日期/日期时间字段的好方法是什么?无法决定是否要使用 expiry_date
、end_time
、created_on
等内容,或者只是使用 expires
、<代码>修改。
What's a good way of naming date/datetime fields? Can't decide if I want to use things like expiry_date
, end_time
, created_on
, or simply expires
, modified
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为任一标准都可以,但就我个人而言,我发现像“modified”这样的列名称不明确,没有看到关联的数据类型 - 是布尔值、日期还是用户 ID?我更喜欢“modified_on”、“modify_date”、“is_modified”、“modified_by”或类似的内容。
I think either standard is okay but personally I find a column name like "modified" ambiguous without seeing the associated data type — is it boolean, a date, or a user ID? I would prefer "modified_on", "modify_date", "is_modified", "modified_by" or something like that.
我通常使用“date_”作为前缀:
只要你保持一致,你的状态就应该很好。或者,如果您正在开发现有产品,请遵循他们的标准。中途改变惯例只会让你背后的人感到烦恼。
I generally use "date_" as a prefix:
As long as you're consistent, you should be in good shape. Alternatively, if you're working on an existing product, follow their standard. Changing conventions part of the way through is just annoying for the people behind you.
我知道这已经很老了,但我想扔掉“At”后缀。所以 CreatedAt 或 ModifiedAt。在约定方法中有点有意义,并且不需要名称中的类型。
I know this is pretty old, but I would like to throw out the suffix of "At". So CreatedAt, or ModifiedAt. Kinda makes sense in a convention approach, and doesn't require a type in the name.