views:

131

answers:

5

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?

+8  A: 

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.

Daniel Brückner
+1 for your first paragraph, even though your opinion is wrong :)
AakashM
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
It seems more natural but I was thinking if it has any negative effects later on in development etc...
Zai
+3  A: 

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.

oezi
+2  A: 

It's pretty much a matter of preference

Flakron Bytyqi
+1  A: 

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.

Mike
A: 

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

arun