表命名难题:单数与复数名称 [英] Table Naming Dilemma: Singular vs. Plural Names

查看:112
本文介绍了表命名难题:单数与复数名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

学术界认为,表名应该是存储其属性的实体的单数形式.

Academia has it that table names should be the singular of the entity that they store attributes of.

我不喜欢任何需要在名称两边加上方括号的T-SQL,但是我已经将Users表重命名为单数,永远判刑那些使用该表的人有时不得不使用方括号.

I dislike any T-SQL that requires square brackets around names, but I have renamed a Users table to the singular, forever sentencing those using the table to sometimes have to use brackets.

我的直觉是保持单数形式更正确,但我的直觉也认为方括号表示不受欢迎的内容,例如列名中带有空格等.

My gut feel is that it is more correct to stay with the singular, but my gut feel is also that brackets indicate undesirables like column names with spaces in them etc.

我应该留下还是应该去?

Should I stay, or should I go?

推荐答案

我也有同样的问题,在阅读了所有答案后,我肯定会留在SINGULAR,原因是:

I had same question, and after reading all answers here I definitely stay with SINGULAR, reasons:

原因1 (概念).您可以想到装有"AppleBag"之类的苹果的包装袋,无论包含0、1还是一百万个苹果都没关系,它始终是同一个包装袋.表只是容器,表名必须描述它包含的内容,而不是描述它包含多少数据.另外,复数概念更多地是关于一种口头语言(实际上是为了确定是否存在一种或多种).

Reason 1 (Concept). You can think of bag containing apples like "AppleBag", it doesn't matter if contains 0, 1 or a million apples, it is always the same bag. Tables are just that, containers, the table name must describe what it contains, not how much data it contains. Additionally, the plural concept is more about a spoken language one (actually to determine whether there is one or more).

原因2 . (方便).单数名称比复数名称更容易出现.对象可以具有不规则的复数,也可以根本不具有复数,但总是具有单数(除了新闻等少数例外).

Reason 2. (Convenience). it is easier come out with singular names, than with plural ones. Objects can have irregular plurals or not plural at all, but will always have a singular one (with few exceptions like News).

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

原因3 . (审美和秩序).尤其是在主从场景中,它读起来更好,按名称排列更好,并且具有更多的逻辑顺序(主优先,细节第二):

Reason 3. (Aesthetic and Order). Specially in master-detail scenarios, this reads better, aligns better by name, and have more logical order (Master first, Detail second):

  • 1.Order
  • 2.OrderDetail

相比:

  • 1.OrderDetails
  • 2.订单

原因4 (简单).放在一起,表名,主键,关系,实体类...最好只知道一个名字(单数),而不是两个名字(单数类,复数表,单数字段,单复数主从细节). )

Reason 4 (Simplicity). Put all together, Table Names, Primary Keys, Relationships, Entity Classes... is better to be aware of only one name (singular) instead of two (singular class, plural table, singular field, singular-plural master-detail...)

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

一旦您知道要与客户"打交道,就可以确保为所有数据库交互需求使用相同的词.

Once you know you are dealing with "Customer", you can be sure you will use the same word for all of your database interaction needs.

原因5 . (全球化).世界越来越小,您可能拥有不同国籍的团队,并非每个人都有英语作为母语.对于非母语的英语程序员来说,考虑存储库"比存储库"或状态"而不是状态"要容易得多.使用单数名称可以减少由错字引起的错误,无需考虑是孩子还是孩子?"来节省时间,因此提高了生产率.

Reason 5. (Globalization). The world is getting smaller, you may have a team of different nationalities, not everybody has English as a native language. It would be easier for a non-native English language programmer to think of "Repository" than of "Repositories", or "Status" instead of "Statuses". Having singular names can lead to fewer errors caused by typos, save time by not having to think "is it Child or Children?", hence improving productivity.

原因6 . (为什么不?).它甚至可以节省您的书写时间,节省磁盘空间,甚至可以延长计算机键盘的使用寿命!

Reason 6. (Why not?). It can even save you writing time, save you disk space, and even make your computer keyboard last longer!

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

您已经保存了3个字母,3个字节和3个额外的键盘按键:)

You have saved 3 letters, 3 bytes, 3 extra keyboard hits :)

最后,您可以使用保留名称来命名那些名称,例如:

And finally, you can name those ones messing up with reserved names like:

  • 用户> LoginUser,AppUser,SystemUser,CMSUser,...

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

Or use the infamous square brackets [User]

这篇关于表命名难题:单数与复数名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆