如何正确命名记录创建(插入)日期时间字段?
如果我创建一个带有 datetime default getdate()
字段的表,该字段旨在保留记录插入的日期和时间,那么该字段更适合使用哪个名称?
我喜欢使用 Created
,并且我见过人们使用 DateCreated
或 CreateDate
。
我能想到的其他可能的候选者是:CreatedDate
、CreateTime
、TimeCreated
、CreateDateTime
、DateTimeCreated
、RecordCreated
、Inserted
、InsertedDate
、...
从我的角度来看,名称中包含 Date 的任何内容看起来都很糟糕,因为它可以如果我有 2 个字段,则会与日期部分混淆:CreateDate
、CreateTime
,所以我想知道该领域是否有基于真实原因的任何具体建议/标准,不仅仅是风格、情绪或一致性。
当然,如果有 100 个现有表,并且这是表 101,那么为了一致性,我将使用与这 100 个表中使用的相同的命名约定,但这个问题是关于第一个应用程序中第一个服务器中的第一个数据库中的第一个表。
If I create a table with datetime default getdate()
field that is intended to keep date&time of record insertion, which name is better to use for that field ?
I like to use Created
and I've seen people use DateCreated
or CreateDate
.
Other possible candidates that I can think of are: CreatedDate
, CreateTime
, TimeCreated
, CreateDateTime
, DateTimeCreated
, RecordCreated
, Inserted
, InsertedDate
, ...
From my point of view anything with Date inside name looks bad because it can be confused with date part in case if I have 2 fields: CreateDate
,CreateTime
, so I wonder if there are any specific recommendations/standards in that area based on real reasons, not just style, mood or consistency.
Of course, if there are 100 existing tables and this is table 101 then I would use same naming convention as used in those 100 tables for the sake of consistency, but this question is about first table in first database in first server in first application.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
为什么不直接在
Created
或CreatedOn
上使用 plain 呢? Windows 操作系统使用文件的三个日期属性。因此,如果您愿意,可以尝试保留这种约定。
Why not just use plain on
Created
, orCreatedOn
. Windows OS uses three date properties for files.So you could try to keep that sort of convention if you prefer.
我倾向于
InsertedDateTime
和InsertedBy
(以及Updated%
、Affected%
可能用于间接更新,Deleted %
用于逻辑删除)。通用 auidt 表的
OperationDateTime
如果我只存储日期,那么它将是
StartDate
。同样,时间只能是BookedTime
另一个规则是避免“SQL”术语,因此“添加/更改”而不是“插入/更新”。我继承了 Inserted/Updated 并且它至少是一致的
只是保持一致:不要将
Created%
与Inserted%
与Added%
混合I tend to
InsertedDateTime
andInsertedBy
(andUpdated%
,Affected%
for indirect updates perhaps,Deleted%
for logical deletes).OperationDateTime
for general auidt tableIf I was storing a date only, it would be
StartDate
. Likewise, time only would beBookedTime
Another rule is to avoid "SQL" terms, so Added/Changed rather then Inserted/Updated. I inherited Inserted/Updated and it's consistent at least
Just be consistent: no mixing
Created%
withInserted%
withAdded%
在这些情况下,我总是使用 CreatedDate,它提供了其他日期的模板:UpdatedDate、DeletedDate、PurchasedDate等等。
I always use
CreatedDate
in these circumstances, and it gives a template for other dates:UpdatedDate
,DeletedDate
,PurchasedDate
and so on.对于数据库中列的名称,我喜欢
created_at
。对于我的代码中使用的对象的属性名称,我喜欢
createdAt
。不确定是否有任何“官方”方式来命名此类字段——但这是 PHP 中常用 ORM 的默认名称,即使对于不使用该约定的项目,我也保留了该约定。
For the name of the column in the database, I like
created_at
.And for the name of the property in the object used in my code, I like
createdAt
.Not sure there is any "official" way of naming that kind of field -- but that's the default name of a well-used ORM in PHP, and I've kept that convention even for projects in which I don't use that convention.
Windows 在文件属性中使用,
所以我认为使用它也不错。
Windows in file properties use
so I think its not bad to go with that.
我总是使用这些列名称:
I always use these these column names: