数据库表命名,复数或单数 [英] Database tables naming, plural or singular

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

问题描述

当命名数据库的表和模式时,最好使用单数或复数。
例如。应该是客户还是客户?

When naming tables and schema of the db is it best to use singular or plural. For example. should it be Customers or Customer?

当命名应该是资本,如客户或客户?关于命名的任何最佳实践?

And when naming should it be Capital such as Customer or customer? Any best practice regarding naming?

推荐答案

这个问题需要宗教战争。

This question calls for a religious war.

我毫无疑问应该是复数,因为...

I have no doubt it should be plural because...


  • 表是一组行。
  • SQL语法变得更自然 - SELECT * FROM Customers 而不是 SELECT * FROM Customer 。 c> 类似于OOP - 您有一个类 Customer 以及名为的客户列表或其他集合,
  • 。 c。 c $ c>客户是指整个表,而 Customer 是指当前行。
  • A table is a collection of rows.
  • The SQL syntax becomes more natural - SELECT * FROM Customers instead of SELECT * FROM Customer.
  • The analogy to OOP - you have a class Customer and a list or other collection of customers called Customers.
  • SELECT * FROM Customers AS Customer WHERE Customer.FirstName = 'John' - Customers refers to the whole table while Customer refers to the current row.

负面事物

在开发过程中,必须在单数和复数之间切换多次。您可以从概念模型开始 - 例如实体关系模型 - 其中自然的选择是命名实体 Customer 。从这个模型生成一个数据库,并且必须将名称复数化以获得 Customers 表。最后你选择你的favourit O / R映射器,它必须再次单数化名称以获得一个名为 Customer 的类。

One has to switch several times between singular and plural during the development. You may start with a conceptual model - for example an entity relationship model - where the natural choice is to name the entity Customer. From this model you generate a database and must pluralize the name to get the Customers table. Finally you pick your favourit O/R mapper and it has to singularize the name again to get a class named Customer.

如果您必须手动执行此操作,因为该工具缺乏支持(例如.NET 4.0之前的EntityFramework),可能是一个合理的选择,保持表名称奇异,但是得到一个类 Customer 而不是客户

If you have to do this manually because the tool is lacking support (for example EntityFramework prior to .NET 4.0) it might be a reasonable choice to keep the table names singular but therfore get a class Customer instead of Customers without changing it by hand.

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

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