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

学术界认为,表名应该是他们存储属性的单一实体。

我不喜欢任何需要围绕名称的方括号的T-SQL,但是我已经将Users表重新命名为单数,永远判断使用表的人有时必须使用括号。

我的直觉是,用单数来保持是正确的,但是我的直觉是括号表示不喜欢的东西,比如列名和空格等等。

我应该走还是留?

就“标准”而言,其他人已经给出了很好的答案,但是我只是想补充一下……“用户”(或“用户”)实际上可能不是对表中数据的完整描述? 不是因为表名和特殊性太疯狂,但是可能像“Widget_Users”(其中“Widget”是您的应用程序或网站的名称)更合适。

我有同样的问题,并在阅读所有答案后,我绝对留在SINGULAR,理由:

原因1 (概念)。 你可以想像包含苹果的袋子,比如“AppleBag”,如果包含0,1或者一百万个苹果就没关系,它总是一样的包。 表就是这样,容器,表名必须描述它包含的内容,而不是包含多less数据。 此外,复数概念更多地是关于口语(实际上是确定是否有一个或多个)。

原因2 。 (方便)。 用单数名字比用复数名字更容易。 对象可以有不规则的复数或不复数,但总会有一个单数(除了less数例外,如新闻)。

  • 顾客
  • 订购
  • 用户
  • 状态
  • 新闻

原因3 。 (美学和秩序)。 特别是在主细节的情况下,这读起来更好,通过名称更好地alignment,并具有更多的逻辑顺序(Master first,Detail second):

  • 1.Order
  • 2.OrderDetail

相比:

  • 1.OrderDetails
  • 2.Orders

原因4 (简单)。 综合起来,表名,主键,关系,实体类…更好的是只知道一个名称(单数),而不是两个(单数类,复数表,单数域,单数复数主数据。 。)

  • Customer
  • Customer.CustomerID
  • CustomerAddress
  • public Class Customer {...}
  • SELECT FROM Customer WHERE CustomerID = 100

一旦你知道你正在处理“客户”,你可以肯定你会用同一个词来满足你所有的数据库交互需求。

原因5 。 (全球化)。 世界越来越小,你们可能有一个不同的国籍队伍,不是每个人都有英语作为母语。 对于非本地英语程序员而言,将“易库”比“库”考虑起来更容易,或者避免使用“状态”来input“状态”。 使用单数名称可以减less拼写错误导致的错误,避免花费额外的时间思考“是孩子还是孩子”,从而节省时间,从而提高生产力。

原因6 。 (为什么不?)。 它甚至可以节省您的写作时间,节省您的磁盘空间,甚至让您的电脑键盘持续更多!

  • SELECT Customer.CustomerName FROM Customer WHERE Customer.CustomerID = 100
  • SELECT Customers.CustomerName FROM Customers WHERE Customers.CustomerID = 100

你已经保存了3个字母,3个字节,3个额外的键盘命中:)

最后,你可以将这些名称命名为保留名称:

  • 用户>login用户,AppUser,SystemUser,CMSUser,…

或者使用臭名昭着的方括号[User]

Joe Celko在其“ SQL编程风格 ”一书中build议,集合(例如表)应该以复数forms命名,而标量数据元素(例如列)应该以单数forms命名。

他引用ISO-11179-4作为元数据命名的标准,支持这一指导方针。

让我争论为什么这是有道理的。

  1. 表是一组。 表中的每一行都是一个对象(columns = fields)。 在编程中,您使用复数名称命名集合( 数组和集合应该有复数名称来表示它们是对象的集合而不是单个对象 ),例如Java程序中的args
  2. Java参数是复数forms,因为它们可以容纳0,1和数百万个参数。
  3. for every student in students重复他们,而不是for every s in student 。 您从一组学生中select一部分学生。 您不会从学生中select一部分学生。 这是正确命名的概念原因。

揭穿谬误。 最stream行的答案说

原因1 (概念)。 你可以想像包含苹果的袋子,比如“AppleBag”,如果包含0,1或者一百万个苹果就没关系,它总是一样的包。 表就是这样,容器,表名必须描述它包含的内容,而不是包含多less数据。 此外,多元概念更多地是关于口语(实际上是确定是否存在一个或多个),表格不打算由人读取。

让我们转换AppleBag => BagOfApples。 现在,同样的“概念性”论证与自己相反,我们看到苹果公司,因此答案必须是复数

这是因为这个****没有什么概念。 它甚至不能推断英语,简单的逻辑。 用英文,一个BagOfApples != AnApple

“Bag包含0,1,…数以百万计的苹果”这个论点只是certificate集合必须被称为“苹果”,类似于Java参数或stackoverflow.com/posts 。 不知何故,文明的敌人得出这样的结论:必须使用单数。 post只是一个文件夹。 为什么它应该是复数?

让我们教先生 Artuwood的一些逻辑: folder is a folder and must describe what it contains, not how much data it contains

事实上,如果你开始认为你意识到apple contains apple描述废话。 真正的概念是Bag contains Apples 。 我们要么命名我们的包装袋(特定种类),要么考虑它包含的东西, 苹果 (那些肮脏的混蛋试图减less这个数字问题,但我们是在苹果之后,而不是苹果的数量)。 是的,如果我们把包装纸抽象出来,我们就会意识到,我们在Apples之后,包含着什么。 我们获取并迭代Bag或者Apple,而不是苹果。

原因2 。 (方便)。 用单数名字比用复数名字更容易。 对象可以有不规则的复数或不复数,但总会有一个单数(除了less数例外,如新闻)。

客户订单用户状态新闻

他在说什么方便? 让我们指出,复数比单数更简单。

原因3 。 (美学和秩序)。

我们这边是一个观念。 和他一样,这很简单。 我们只是声称,这是所有需要打开表格。

原因4 (简单)。 综合起来,表名,主键,关系,实体类…更好的是只知道一个名字(单数),而不是两个(单数类,复数表,单数域,单数复数主数据。 。)

我是否仅仅为了简单而看到,一切都必须变得单一? 是的,忘记使用英语的复数。 这将使事情变得更简单。

事实上,在许多语言里,性关系到所有的事物,而不仅仅是男孩和女孩。 这是愚蠢的,使语言不必要的复杂。 但是,我注意到它简化了参考。 当我用俄语说“狐狸,狗和狼”,然后说“他”的时候,毫不含糊地表示我是指“狼”,因为“狐狸”和“狗”是“她”。 现在你认为有助于减less歧义的区别创造了它。 怎么会这样?

可能的逻辑是:“让我们的语言随心所欲,通过删除有意义的规则来强化混乱”。 是的,在逻辑要求复数的情况下使用单数的提议,同时保持将不适当的属性(如性别)附加到不适当的项目上是在我们疯狂的世界中追求废话。

作为

SELECT activity.name读取比SELECT activities.name更好

您可能需要将SELECT student.name FROM students as student

好的,这里可能是这样的:如果table是复数,那么table的别名是多less? 好的,这是有道理的。 但是说列(对象的属性)是单数的,因此对象集合也是单数的,是无稽之谈。

原因5 。 (全球化)。 世界越来越小,你们可能有一个不同的国籍队伍,不是每个人都有英语作为母语。 对于非本地英语程序员而言,将“易库”比“库”考虑起来更容易,或者避免使用“状态”来input“状态”。 使用单数名称可以减less拼写错误导致的错误,避免花费额外的时间思考“是孩子还是孩子”,从而节省时间,从而提高生产力。

毫无疑问, 这个偏执会打破他的想法。 但是为什么像我这样的其他非母语人士为了简单化和国际化而买废话呢? 为什么不改善我们的英语,并保持逻辑不变? 毕竟,在这种情况下理解语言要容易得多。

否则,为了简单起见,我们也应该放弃动词,文章,形容词,只用名词。 如果我们把我们的言论限制在moooo而不是别的什么地方,动物也能说英语,那将会更简单(也更有效率)。 这样我们实现了更广泛的国际化。

原因6 。 (为什么不?)。 它甚至可以节省您的写作时间,节省磁盘空间,甚至让您的电脑键盘持续更多!

这个观点支持我们为什么在人类交stream中也要放弃复数。 不,不是moooo, mo moo, moo moo ,我们会说I, III, III, II 。 比单独的build议短得多。


底线是所有反对复数的“论点”都是纯粹的废话。 如果你仔细想想,它会反对单数。 当所有你必须支持你的立场是废话,这意味着你需要废话来支持你的观点,你是错误的一面。

单数唯一有意义的论据是,表是一组非常特殊的对象。 表是一个类 ! 是的,它包含特定types的所有对象,我们使用单数来表示类名。 类Dog包含所有的狗。 什么是dog1? 它是一只狗。 另一方面,用户将表格作为集合来处理。 他们添加/删除项目收集,我们使用复数收集。

如果你使用对象关系映射工具,或者将来我会build议Singular

像LLBLGen这样的工具可以自动更正像用户到用户这样的复数名称,而不必改变表名。 为什么这很重要? 因为当它被映射时,你希望它看起来像User.Name而不是Users.Name,或者更糟糕的是我的一些旧的数据库表命名tblUsers.strName,这只是在代码混淆。

我的新的经验法则是判断一旦它被转换成对象后它将如何看待。

我发现一个表不符合我使用的新命名是UsersInRoles。 但总是会有这样的例外,甚至在这种情况下,它看起来很好,作为UsersInRoles.Username。

我更喜欢使用未经反应的名词,这在英语中恰好是单数。

忽略表名的数量会导致正字法问题(与许多其他的答案一样),但是select这样做是因为表格通常包含多行,而且在语义上也是充满了漏洞。 如果我们考虑一种根据情况来使用名词的语言,那么这一点就更为明显了(正如大多数人所做的那样):

既然我们通常在做一些事情,为什么不把这个名字放在指责的情况下呢? 如果我们有一个比我们写的表格更多的东西,为什么不把名字放在和弦里? 这是一个表格,为什么不使用属格? 我们不会这样做,因为表被定义为一个抽象的容器,不论其状态或用法如何。 在没有精确和绝对的语义原因的情况下,忽略名词就是喋喋不休。

使用未被reflection的名词是简单的,逻辑的,规则的和语言无关的。

什么公约要求表格有单数名称? 我一直认为这是复数名字。

用户被添加到Users表中。

本网站同意:
http://vyaskn.tripod.com/object_naming.htm#Tables

本网站不同意(但我不同意):
http://justinsomnia.org/writings/naming_conventions.html


正如其他人所说:这些只是指导方针。 select一个适合你和你的公司/项目的惯例,并坚持下去。 在单数和复数之间切换或有时缩写词有时不会更加加重。

这个如何作为一个简单的例子:

 SELECT Customer.Name, Customer.Address FROM Customer WHERE Customer.Name > "def" 

 SELECT Customers.Name, Customers.Address FROM Customers WHERE Customers.Name > "def" 

后者中的SQL比前者更响亮。

我投票赞成单数

我坚信在一个实体关系图中,实体应该用一个单独的名字来反映,类似于一个单独的类名。 一旦实例化,名称反映它的实例。 所以对于数据库来说,实体制成表格(实体或logging的集合)是复数forms。 实体,用户被制成表格用户。 我同意其他人build议,也许用户可以改善的名称雇员或更适用于您的情况。

这在SQL语句中更有意义,因为您正在从一组logging中进行select,并且如果表名是单数,则读取不好。

我坚持单一表名和任何编程实体。

原因? 英语中有像小鼠⇒小鼠羊⇒羊这样的不规则复数的事实。 那么,如果我需要一个集合 ,我只是使用鼠标 ,然后继续前进。

这确实有助于众多人士脱颖而出,并且我可以轻松地,以编程方式确定收集的东西的样子。

所以,我的规则是:一切都是单一的,每一个东西都是单一 。 也帮助与ORMs。

单数。 我不会买任何最符合逻辑的论点 – 每个人都认为他自己的偏好是最合乎逻辑的。 无论你做什么事情都是一团糟,只要select一个惯例就可以了。 我们试图用非常特殊的语义将高度不规则的语法和语义(正常的语言和文字)语言映射到高度规则的(SQL)语法。

我的主要观点是,我不认为表格是一个集合,而是关系。

所以, AppUser关系告诉哪些实体是AppUsers

AppUserGroup关系告诉我哪些实体是AppUserGroups

AppUser_AppUserGroup关系告诉我AppUsersAppUserGroups是如何关联的。

AppUserGroup_AppUserGroup关系告诉我AppUserGroupsAppUserGroups是如何相关的(即组的成员)。

换句话说,当我思考实体及其相关性时,我想到的是单数关系,当然,当我想到集合或集合中的实体时,集合或集合是复数。

在我的代码中,然后在数据库模式中,我使用单数。 在文本描述中,我最终使用复数来增加可读性 – 然后使用字体等来区分表/关系名称与复数forms。

我喜欢把它看成是混乱而系统的 – 这样一来,我就想要expression的关系总是有系统地产生的名字,这对我来说是非常重要的。

我也会去复数 ,并与上述用户的困境,我们采取方括号方法。

我们这样做是为了在数据库体系结构和应用程序体系结构之间提供一致性,并且深刻理解Users表是用户值的集合,就像代码工件中的用户集合是用户对象的集合一样。

让我们的数据团队和我们的开发人员使用相同的概念语言(虽然不总是相同的对象名称)可以更轻松地在它们之间传达想法。

单数。 我会调用一个数组包含一堆用户行表示对象的用户,但表是“用户表”。 认为表格只是它所包含的行集是错误的,IMO; 该表是元数据,并且该行集合被分层次地附加到该表上,而不是该表本身。

当然,我总是使用ORM,而用复数表名写的ORM代码看起来很愚蠢。

IMHO, table names should be plural like Customers .

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

I personaly prefer to use plural names to represent a set, it just "sounds" better to my relational mind.

At this exact moment i am using singular names to define a data model for my company, because most of the people at work feel more confortable with it. Sometimes you just have to make life easier to everyone instead of imposing your personal preferences. (that's how i ended up in this thread, to get a confirmation on what should be the "best practice" for naming tables)

After reading all the arguing in this thread, i reached one conclusion:

I like my pancakes with honey, no matter what everybody's favorite flavour is. But if i am cooking for other people, i will try to serve them something they like.

I don't like plural table names because some nouns in English are not countable (water, soup, cash) or the meaning changes when you make it countable (chicken vs a chicken; meat vs bird). I also dislike using abbreviations for table name or column name because doing so adds extra slope to the already steep learning curve.

Ironically, I might make User an exception and call it Users because of USER (Transac-SQL) , because I too don't like using brackets around tables if I don't have to.

I also like to name all the ID columns as Id , not ChickenId or ChickensId (what do plural guys do about this?).

All this is because I don't have proper respect for the database systems, I am just reapplying one-trick-pony knowledge from OO naming conventions like Java's out of habit and laziness. I wish there were better IDE support for complicated SQL.

We run similar standards, when scripting we demand [ ] around names, and where appropriate schema qualifiers – primarily it hedges your bets against future name grabs by the SQL syntax.

 SELECT [Name] FROM [dbo].[Customer] WHERE [Location] = 'WA' 

This has saved our souls in the past – some of our database systems have run 10+ years from SQL 6.0 through SQL 2005 – way past their intended lifespans.

I've actually always thought it was popular convention to use plural table names. Up until this point I've always used plural.

I can understand the argument for singular table names, but to me plural makes more sense. A table name usually describes what the table contains. In a normalized database, each table contains specific sets of data. Each row is an entity and the table contains many entities. Thus the plural form for the table name.

A table of cars would have the name cars and each row is a car. I'll admit that specifying the table along with the field in a table.field manner is the best practice and that having singular table names is more readable. However in the following two examples, the former makes more sense:

 SELECT * FROM cars WHERE color='blue' SELECT * FROM car WHERE color='blue' 

Honestly, I will be rethinking my position on the matter, and I would rely on the actual conventions used by the organization I'm developing for. However, I think for my personal conventions, I'll stick with plural table names. To me it makes more sense.

I am a fan of singular table names as they make my ER diagrams using CASE syntax easier to read, but by reading these responses I'm getting the feeling it never caught on very well? I personally love it. There is a good overview with examples of how readable your models can be when you use singular table names, add action verbs to your relationships and form good sentences for every relationships. It's all a bit of overkill for a 20 table database but if you have a DB with hundreds of tables and a complex design how will your developers ever understand it without a good readable diagram?

http://www.aisintl.com/case/method.html

As for prefixing tables and views I absolutely hate that practice. Give a person no information at all before giving them possibly bad information. Anyone browsing a db for objects can quite easily tell a table from a view, but if I have a table named tblUsers that for some reason I decide to restructure in the future into two tables, with a view unifying them to keep from breaking old code I now have a view named tblUsers. At this point I am left with two unappealing options, leave a view named with a tbl prefix which may confuse some developers, or force another layer, either middle tier or application to be rewritten to reference my new structure or name viewUsers. That negates a large part of the value of views IMHO.

This may be a bit redundant, but I would suggest being cautious. Not necessarily that it's a bad thing to rename tables, but standardization is just that; a standard — this database may already be "standardized", however badly 🙂 — I would suggest consistency to be a better goal given that this database already exists and presumably it consists of more than just 2 tables.

Unless you can standardize the entire database, or at least are planning to work towards that end, I suspect that table names are just the tip of the iceberg and concentrating on the task at hand, enduring the pain of poorly named objects, may be in your best interest —

Practical consistency sometimes is the best standard… 🙂

my2cents —

Tables: plural

Multiple users are listed in the users table.

Models: singular

A singular user can be selected from the users table.

Controllers: plural

http://myapp.com/users would list multiple users.

That's my take on it anyway.

As others have mentioned here, conventions should be a tool for adding to the ease of use and readability. Not as a shackle or a club to torture developers.

That said, my personal preference is to use singular names for both tables and columns. This probably comes from my programming background. Class names are generally singular unless they are some sort of collection. In my mind I am storing or reading individual records in the table in question, so singular makes sense to me.

This practice also allows me to reserve plural table names for those that store many-to-many relationships between my objects.

I try to avoid reserved words in my table and column names, as well. In the case in question here it makes more sense to go counter to the singular convention for Users to avoid the need to encapsulate a table that uses the reserved word of User.

I like using prefixes in a limited manner (tbl for table names, sp_ for proc names, etc), though many believe this adds clutter. I also prefer CamelBack names to underscores because I always end up hitting the + instead of _ when typing the name. Many others disagree.

Here is another good link for naming convention guidelines: http://www.xaprb.com/blog/2008/10/26/the-power-of-a-good-sql-naming-convention/

Remember that the most important factor in your convention is that it make sense to the people interacting with the database in question. There is no "One Ring to Rule Them All" when it comes to naming conventions.

Possible alternatives:

  • Rename the table SystemUser
  • Use brackets
  • Keep the plural table names.

IMO using brackets is technically the safest approach, though it is a bit cumbersome. IMO it's 6 of one, half-a-dozen of the other, and your solution really just boils down to personal/team preference.

I think using the singular is what we were taught in university. But at the same time you could argue that unlike in object oriented programming, a table is not an instance of its records.

I think I'm tipping in favour of the singular at the moment because of plural irregularities in English. In German it's even worse due to no consistent plural forms – sometimes you cannot tell if a word is plural or not without the specifying article in front of it (der/die/das). And in Chinese languages there are no plural forms anyway.

My take is in semantics depending on how you define your container. For example, A "bag of apples" or simply "apples" or an "apple bag" or "apple".

Example: a "college" table can contain 0 or more colleges a table of "colleges" can contain 0 or more collegues

 a "student" table can contain 0 or more students a table of "students" can contain 0 or more students. 

My conclusion is that either is fine but you have to define how you (or people interacting with it) are going to approach when referring to the tables; "ax table" or a "table of xs"

I've always used singular simply because that's what I was taught. However, while creating a new schema recently, for the first time in a long time, I actively decided to maintain this convention simply because… it's shorter. Adding an 's' to the end of every table name seems as useless to me as adding 'tbl_' in front of every one.

I once used "Dude" for the User table – same short number of characters, no conflict with keywords, still a reference to a generic human. If I weren't concerned about the stuffy heads that might see the code, I would have kept it that way.

I only use nouns for my table names that are spelled the same, whether singular or plural:

moose fish deer aircraft you pants shorts eyeglasses scissors species offspring

If we look at MS SQL Server's system tables, their names as assigned by Microsoft are in plural.

The Oracle's system tables are named in singular. although a few of them are plural. Oracle recommends plural for user-defined table names. That doesn't make much sense that they recommend one thing and follow another. That the architects at these two software giants have named their tables using different conventions, doesn't make much sense either… After all, what are these guys … PhD's?

I do remember in academia, the recommendation was singular.

For example, when we say:

select OrderHeader.ID FROM OrderHeader WHERE OrderHeader.Reference = 'ABC123'

maybe b/c each ID is selected from a particular single row …?

I will just give my opinion why I use singular names.

For example, I need to get all the fields from an user:

 -- Select every fields from 'user' table SELECT * FROM user 

I need the name of the user that is 21 years old:

 -- Select every fields from 'user' table which have 21 years old SELECT * FROM user WHERE age = '21' 

Of course the plural way can be used by the same means, but for my brain to read, I really think that's the right way to go.

I always thought that was a dumb convention. I use plural table names.

(I believe the rational behind that policy is that it make it easier for ORM code generators to produce object & collection classes, since it is easier to produce a plural name from a singular name than vice-versa)