17

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?

2

5 Answers 5

25

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.

3
  • 10
    +1 for your first paragraph, even though your opinion is wrong :)
    – AakashM
    Jul 15, 2010 at 9:26
  • 2
    I used singular naming but after switching to rails where plural is the standard the plural naming feels more natural. This is especially true for queries
    – Tarscher
    Jul 15, 2010 at 9:29
  • It seems more natural but I was thinking if it has any negative effects later on in development etc... Jul 15, 2010 at 9:32
8

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.

1
  • "It's all about the tuples" Exactly: "tuples". It is about ALL the tuples and not about a single tuple. A label for a table is also not a label for a single tuple, but a label for all tuples. A SELECT statement always selects ALL rows and then you can reduce the number of rows with WHERE or JOIN afterwards.
    – Toxiro
    Sep 25, 2023 at 9:52
6

It's pretty much a matter of preference

5

Do you select a recipe.ingredient or a recipes.ingredient?

...or do you select an ingredient from recipes instead of an ingredient from recipe.

Do you select a recipe.ingredient list, or a recipes.ingredient list?

...or do you select an ingredient list from recipes instead of an ingredient list from recipe?

I think consistency is more important that the convention itself. Personally, I prefer singular, lower case table names, but I'm not going to vehemently defend that choice.

3
  • You do not select ingredient from a single recipe. You ALWAYS select ingredient from ALL recipes and only afterwards if you want you can reduce the number of results with WHERE or JOIN. So it is recipes.ingredient as in "choose the ingredients field of all recipes" and it is "select ingredient from recipes". It is plural all the way.
    – Toxiro
    Sep 25, 2023 at 9:59
  • @Toxiro, you're bringing too much SQL logic into this. The SQL language is designed in a way where the table is a collection - it's always plural. But I truly believe this is a personal preference, since in our minds, we see the table as a template for an instance, the instance being the row, and since we don't individually name rows, we keep the table name singular, using it as a reference to the instances we actually want from the queries. I guess this is a really complicated way of saying "it's up to preference", but this is how I feel.
    – Nox5692
    Apr 2 at 14:15
  • @Nox5692 Wow, that is the first comment I read about that topic, that made me change my mind. Most people argue with language or SQL grammar and I always thought, no, plural is the only way that works in those cases. Your way of thinking seems totally valid, is easy to understand and I agree with you, it seems personal preference. The more you read about those topics it always comes down to "Do it this way or the other, but be consistent".
    – Toxiro
    Apr 3 at 10:05
0

My choice are Singular and TitleCase :)

Customer is an entity. Table is the logical collection of multiple entity. So plural is preferred.

For table names pascal case is better. i.e., CustomerMaster.

It is preferred to use prefix such as tblCustomerMaster.

If you are using group name as prefix then use it in capital letters like, NEWCustomer, OLDCustomer

Not the answer you're looking for? Browse other questions tagged or ask your own question.