MySQL 数据库表名是单数还是复数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/808992/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:12:02  来源:igfitidea点击:

Singular or plural database table names?

sqlmysqlsql-server

提问by lalala2007

Exact Duplicate

完全重复

Table Naming Dilemma: Singular vs. Plural Names

表命名困境:单数与复数名称

Is it better to use singular or plural database table names ? Is there an accepted standard ?

使用单数还是复数数据库表名更好?有公认的标准吗?

I've heard arguments for and against it, what do you guys think ?

我听到了支持和反对的论据,你们怎么看?

回答by Tim Robinson

Singular, so you can have:

单数,所以你可以有:

  • Customer
  • CustomerAddress
  • CustomerAddressAuditTrail
  • 顾客
  • 客户地址
  • 客户地址审计跟踪

etc.

等等。

回答by Gulzar Nazim

IMHO, Table names should be plural like Customers.

恕我直言,表名应该像客户一样复数。

Class names should be singular like Customer if it maps to a row in Customers table.

如果类名映射到客户表中的一行,则类名应该像 Customer 一样是单数。

回答by MarkR

I like singular names but appear to be in the minority.

我喜欢单数,但似乎是少数。

回答by MattK

My personal philosophy is that using a plural database table name is redundant, unless you're only planning for the table to contain one row.

我个人的理念是使用复数数据库表名是多余的,除非您只计划表包含一行。

回答by wcm

I like to use singular names like Agent that have PK names like AgentID.

我喜欢使用单数名称,如具有 PK 名称(如 AgentID)的 Agent。

But that's just me :o)

但这只是我 :o)

回答by Adrian Grigore

I like to use plural forms, simply because one table contains several entities, so it seems more natural to me.

我喜欢使用复数形式,仅仅因为一张表包含多个实体,所以对我来说似乎更自然。

Linq to SQL converts plural form table names to singular when creating data entities. I assume that Microsoft would not have implemented this functionality if they considered plural forms for table names bad practice.

Linq to SQL 在创建数据实体时将复数形式的表名转换为单数形式。我认为如果微软认为表名的复数形式是不好的做法,他们就不会实现这个功能。

回答by Alexander Kahoun

At my current company we use Plural for table names. The reasoning is this: If we have a Customers table we consider each row a Customer, so the table itself is a collection of customers.

在我现在的公司,我们使用 Plural 作为表名。推理是这样的:如果我们有一个客户表,我们认为每一行都是一个客户,所以该表本身就是一个客户的集合。

回答by Rob

Well, obviously your database table names have absolutely gotto be named in a "standard" fashion which I will hitherto arbitrarily define.

好吧,显然您的数据库表名绝对必须以“标准”方式命名,我将迄今为止任意定义。

First, all tables names shall be prefixed with "t_". Following this, the singular entity name in StudlyCaps, e.g. "Customer". Immediately afterwards, this shall contain the number of columns created in the first version of the schema, for historical purposes, followed by an underscore, and the precise normal form of the data; either "1", "2", "3" or "B" for BCNF. Any higher normal forms shall be denoted by a "P".

首先,所有表名都应以“t_”为前缀。在此之后,StudlyCaps 中的单数实体名称,例如“客户”。紧接着,这应包含在模式的第一个版本中创建的列数,用于历史目的,后跟一个下划线,以及数据的精确规范形式;BCNF 为“1”、“2”、“3”或“B”。任何更高的范式都用“P”表示。

Some examples of acceptable names are:

可接受名称的一些示例是:

t_Customer_6_3
t_Order_5_B
t_OrderLine_4_2

I think my point is, it really doesn't matter, as long as the name is reasonably descriptive and naming is consistent.

我想我的观点是,这真的没有关系,只要名称具有合理的描述性并且命名一致即可。

回答by HLGEM

The most important thing is to be consistent in your usage. It is annoying to have to remember which tables are plurals and which are not. Same thing with your field names, pick one stadard and use it. Don't make the poor developers have to determine if this table uses person_id or personid or peopleid or person$id, etc. It is amazing the amount of time you can waste when you don't have standards trying just to remember which table uses what.

最重要的是在您的使用中保持一致。必须记住哪些表格是复数,哪些不是,这很烦人。与您的字段名称相同,选择一个标准并使用它。不要让可怜的开发人员必须确定这个表是使用 person_id 还是 personid 或 peopleid 或 person$id 等。当你没有标准试图记住哪个表使用时,你可以浪费的时间是惊人的什么。

回答by Azder

There is no should or must be this way or that way correct answer to this question. It's up to the designer of the database and software.

这个问题没有应该或必须这样或那样的正确答案。这取决于数据库和软件的设计者。

As for me, I usually use singular names becouse when I do the E-R diagram I have an entity Customer , not Customers, so I keep it same as to not get confused.

至于我,我通常使用单数名称,因为当我做 ER 图表时,我有一个实体 Customer ,而不是 Customers,所以我保持不变以免混淆。

Ofcourse some frameworks do favor one style or another, so you should be best of to follow those practices when you notice them.

当然,有些框架确实偏爱一种或另一种风格,因此当您注意到这些实践时,最好遵循这些实践。