Search code examples
mysqldatabaseentity-relationshipdiagramming

Data model. ¿Pluralize or not pluralize the names of the tables?


Hello everyone. Whenever I start to develop a new data model for any application I have the same question:

Is it convenient pluralize the names of the tables?

Where the table is stored, for example, users; Will you call 'Users' or 'User'?

I do not pluralize, because with this data model, I then generated entities for ORM and it seems more correct to instantiate a new 'User' that a new 'Users'.

I would like to know that think about it.

Greetings to all!


Solution

  • I guess it all depends on what you are actually going to use the database for:

    I do not pluralize, because with this data model, I then generated entities for ORM and it seems more correct to instantiate a new 'User' that a new 'Users'.

    But you don't give much information regarding which language you use besides sql, which framework, which tools.

    I usually say that the best is to conform to standards of the framework or ORM, for instance in .NET Entity Framework the tables are generated with a singular notation and class names that map to these tables are singular as well, whereas in Ruby on Rails ActiveRecord they are generated pluralized in the database but mapping classes are singular.

    There is no better way I think but, if the data for your application is ever going to be more important than the application itself (as in, we may migrate from that framework or language eventually to something completely different) or if there are going to be others working directly on the database (people doing reports, DBA's, analysts etc.) then I'd suggest you make the tables plural as database people are more keen to use it that way.

    If you think at the database level pluralizing makes sense, a users table is probably going to have more than one user, and so on and so forth. Why would you want to store data in a table fashion if you weren't going to store more than one record with the same structure? Than it makes sense to pluralize.

    If you create an Array type of data in X language, let's say, for users, you don't call it useryou call it users probably, because it may contain more than one, even if you only store one thing on it initially.

    So that would be my reasoning behind why pluralize a table name is a good approach, besides, you can almost always setup your mappings in the ORM if pluralizing breaks the convention so that you can set that the User class maps to the users table for instance.

    Update: here is another good discussion on StackExchange's DBA where they make a point regarding joint associations