Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database tables naming, plural or singular [duplicate]

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?

like image 656
Jasmine Appelblad Avatar asked Jul 15 '10 09:07

Jasmine Appelblad


People also ask

Should database table names be singular or plural?

So Which Should I Use: Singular or Plural? The correct answer is that there is no right or wrong when naming database tables — just be consistent from the start. The only wrong answer with database table names is to use a combination of plural and singular.

Is tables singular or plural?

The plural form of table is tables.

Should entities be singular or plural?

The name of a corporate entity is also a collective noun. Although the corporate entity may be composed of many people, the entity itself is singular.


2 Answers

This question calls for a religious war.

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

  • 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.

Negative things

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.

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.

like image 51
Daniel Brückner Avatar answered Sep 25 '22 22:09

Daniel Brückner


singular naming.

it's all about the tuples, not the tables, and a tuple is one customer, not customers. also i prefer naming in lower cases, but thats for no reason, i just learned it like that in school.

in the end, as others said, it's more a matter of preference. more important than the choice if to use plural or singular is to stay consistend and do it the same way for all tables - if you mix pluar and singular naming, it's a real mess.

like image 32
oezi Avatar answered Sep 24 '22 22:09

oezi