What is the best practice in naming your "user" table?

DatabaseDatabase DesignNaming Conventions

Database Problem Overview


Here's three best practices I try to follow when naming tables:

  • Never name a table with plural (such as "users")
  • Never name a table using a reserved keyword (such as "user")
  • Never prefix your table name with "tbl" or some other object type prefix

Keeping all this in mind, how do you recommend naming the table that will hold user identities?

Database Solutions


Solution 1 - Database

I agree, do not use any reserved words, or quoted or bracketed or escaped forms of reserved words.

Name the User table Person.

You may be interested in this answer and google for the ISO standard 11179 for naming Guidelines

Solution 2 - Database

I typically use something like member or account, depending on the application. That said, if you're using modern design tools and principles (e.g., a db abstraction layer or ORM with an object-oriented code base that separates business logic from data access), then table naming becomes fairly irrelevant. Your developers should only ever be accessing the database through a well-defined interface and not by hand-writing SQL that requires them to know the table name. For example, you could name the table account but map access to it via an object named User. Your developers shouldn't be thinking in terms of tables, but in terms of access objects, which aren't going to have the same restrictions on naming:

$user = new User($username);
$user->authenticate($password);

Solution 3 - Database

Use a synonym. What word to use depends on what exactly you store in the table, but account strikes me as a good alternative. If you want to use a variation user I'd break the first guideline you mention, not the second or third: users is common enough that the inconsistency is essentially mnemonic.

Solution 4 - Database

I use CakePHP rules even when I don't use the framework :

Table names are by convention lowercase and pluralized with multi-word table names separated by underscores. For example, a Model name of Ingredient expects the table name ingredients. Model name of EventRegistration would expect a table name of event_registrations.

Solution 5 - Database

Do not use reserved words or quoted or escaped words for database table names.

If you really want to do this then you need to escape the names:

  • quotation marks: "user"
  • Java + JPA escaping: @Table(name = "\"user\"")

I highly not recommend using plural worlds for database table names like USERS. This is a BAD PRACTICE, against the SQL naming convention. Database table names need to be singular nouns.

I recommend using ACTOR for a database table name to store users details. This name is clear, understandable and enough general. It can be used for companies and individuals as well (not like ex. PERSON, which fit for only person but not companies).

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHK1View Question on Stackoverflow
Solution 1 - DatabasePerformanceDBAView Answer on Stackoverflow
Solution 2 - DatabaseAlex HowanskyView Answer on Stackoverflow
Solution 3 - DatabaseSirPavlovaView Answer on Stackoverflow
Solution 4 - DatabaseGG.View Answer on Stackoverflow
Solution 5 - DatabasezappeeView Answer on Stackoverflow