用单数形式更佳,理由如下:
1、概念直观。
你有一个袋子,里面有好多个苹果,你会说这是个苹果袋。但无论里面有0,1,百万个苹果,它依然是个袋子。表也是如此,表明需要描述清楚,表里面包含的对象,而非有多少个数据。
2、便利性
单数形式更简单。有一些单词,它的复数形式可能是非常规的,或者就没有复数形式,但是单数不一样,单数形式则没那么多讲究。有些单词的复数,可能会想到你头大,可能得好好google才出来
3、优雅
特别是一些master-detail形式的资源名称,统一用单数,读起来更方便,对齐更整齐,从顺序上更有逻辑性。
对比下
单数:
Order
OrderDetail
复数:
OrderDetails
Orders
4、简单朴素
设想下,不管是表名,主键,关系,实例Classes,你都可以统一用单数,所有看上去那么统一,也不用费心地各种复数单数中转换你的思维
Customer
Customer.CustomerID
CustomerAddress
public Class Customer {...}
SELECT FROM Customer WHERE CustomerID = 100
一旦你确定,要处理的这个对象,名字定为Customer,那么所有和数据库相关的交互、编程就都将使用这个单词
5、全球化
假设你身处一个全球化的团队,成员中有些人,母语不是英文,对他们来说,辨认、书写一个单词的复数形式,要更困难,会给他们带来麻烦,也给团队合作带来麻烦。
6、为什么不
这可以节省你的拼写时间,硬盘空间,甚至让你的键盘更“长寿”
SELECT Customer.CustomerName FROM Customer WHERE Customer.CustomerID = 100
SELECT Customers.CustomerName FROM Customers WHERE Customers.CustomerID = 100
看这两条语句,你可以省下3个字母,3个字节,3次键盘敲击
最后,我还认为,你应该给一些容易冲突的名字加个前缀,例如User,要把对应的前缀加上,也就是
User > LoginUser, AppUser, SystemUser, CMSUser,...
stackoverflow链接:
http://stackoverflow.com/questions/338156/table-naming-dilemma-singular-vs-plural-names
https://blog.csdn.net/lizeyang/article/details/41556803
I had same question, and after reading all answers here I definitely stay with SINGULAR, reasons:
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).
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).
- Customer
- Order
- User
- Status
- News
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
Compared to:
- 1.OrderDetails
- 2.Orders
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
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.
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 "Statuses" instead of "Status". 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.
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
You have saved 3 letters, 3 bytes, 3 extra keyboard hits :)
And finally, you can name those ones messing up with reserved names like:
- User > LoginUser, AppUser, SystemUser, CMSUser,...
Or use the infamous square brackets [User]
来源:
https://stackoverflow.com/questions/338156/table-naming-dilemma-singular-vs-plural-names
修改时间 2018-09-26