Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 637
HK1 Avatar asked Mar 13 '11 16:03

HK1


People also ask

What is the best practice naming convention for SQL?

When naming tables, you have two options – to use the singular for the table name or to use a plural. My suggestion would be to always go with names in the singular. If you're naming entities that represent real-world facts, you should use nouns. These are tables like employee, customer, city, and country.

What are the rules for naming a table in MySQL?

By default, MySQL encloses column names and table names in quotation marks. Table names can use any character that is allowed in a file name except for a period or a forward slash. Table names must be 32 characters or less because SAS does not truncate a longer name.


2 Answers

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

like image 141
PerformanceDBA Avatar answered Oct 01 '22 11:10

PerformanceDBA


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); 
like image 38
Alex Howansky Avatar answered Oct 01 '22 09:10

Alex Howansky