如何正确命名记录创建(插入)日期时间字段?

发布于 2024-08-25 22:53:46 字数 689 浏览 4 评论 0原文

如果我创建一个带有 datetime default getdate() 字段的表,该字段旨在保留记录插入的日期和时间,那么该字段更适合使用哪个名称?

我喜欢使用 Created,并且我见过人们使用 DateCreatedCreateDate

我能想到的其他可能的候选者是:CreatedDateCreateTimeTimeCreatedCreateDateTimeDateTimeCreatedRecordCreatedInsertedInsertedDate、...

从我的角度来看,名称中包含 Date 的任何内容看起来都很糟糕,因为它可以如果我有 2 个字段,则会与日期部分混淆:CreateDateCreateTime,所以我想知道该领域是否有基于真实原因的任何具体建议/标准,不仅仅是风格、情绪或一致性。

当然,如果有 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 技术交流群。

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

发布评论

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

评论(6

杀手六號 2024-09-01 22:53:46

为什么不直接在 CreatedCreatedOn 上使用 plain 呢? Windows 操作系统使用文件的三个日期属性。

Created:
Modified:
Accessed:

因此,如果您愿意,可以尝试保留这种约定。

Why not just use plain on Created, or CreatedOn. Windows OS uses three date properties for files.

Created:
Modified:
Accessed:

So you could try to keep that sort of convention if you prefer.

烧了回忆取暖 2024-09-01 22:53:46

我倾向于 InsertedDateTimeInsertedBy (以及 Updated%Affected% 可能用于间接更新,Deleted % 用于逻辑删除)。

通用 auidt 表的 OperationDateTime

如果我只存储日期,那么它将是 StartDate。同样,时间只能是 BookedTime

另一个规则是避免“SQL”术语,因此“添加/更改”而不是“插入/更新”。我继承了 Inserted/Updated 并且它至少是一致的

只是保持一致:不要将 Created%Inserted%Added% 混合

I tend to InsertedDateTime and InsertedBy (and Updated%, Affected% for indirect updates perhaps, Deleted% for logical deletes).

OperationDateTime for general auidt table

If I was storing a date only, it would be StartDate. Likewise, time only would be BookedTime

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% with Inserted% with Added%

只是一片海 2024-09-01 22:53:46

在这些情况下,我总是使用 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.

攀登最高峰 2024-09-01 22:53:46

对于数据库中列的名称,我喜欢 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.

篱下浅笙歌 2024-09-01 22:53:46

Windows 在文件属性中使用,

DateCreated
DateModified

所以我认为使用它也不错。

Windows in file properties use

DateCreated
DateModified

so I think its not bad to go with that.

坐在坟头思考人生 2024-09-01 22:53:46

我总是使用这些列名称:

CreateDate  --when they did it
CreateID    --who who did it

LastChgDate --when they did it
LastChgID   --who who did it

I always use these these column names:

CreateDate  --when they did it
CreateID    --who who did it

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