Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming conventions for tables and columns in database [duplicate]

Possible Duplicate:
Database, Table and Column Naming Conventions?

Each time when new project starts, I’m thinking about naming conventions of table and columns in database. Which case is your recommendation and why?

Case 1. column_name
Case 2. ColumnName
Case 3. Column_Name
Case 4. columnName

like image 747
sasa Avatar asked Jun 04 '09 20:06

sasa


People also ask

Should database table names be singular or plural?

So Which Should I Use: Singular or Plural? The correct answer is that there is no right or wrong when naming database tables — just be consistent from the start. The only wrong answer with database table names is to use a combination of plural and singular.

What are naming conventions in a database?

Naming conventions are a set of guideline that make strong foundations for such a consistent system. These guidelines ensure that the names of database entities are readable, easy to use in queries and do not collide with names of other defined entities or keywords.

What is the naming conventions of a database in SQL?

Each Primary Key name should have a “PK_” prefix. The first letter of a table name should be capitalized. The last word of a table name should be end with the character "s" (or "es") to indicate plural. If a table name contains more than one word then the first letter of each word should be capitalized.

What is the naming convention of a column?

Column names must contain only A to Z, 0 to 9, and underscore (_) characters. Column names can contain multiple underscores. The column name must not be very generic. Avoid words such as term, multiplier, description, name, code, and so on.


2 Answers

You should use case #1 because it's free of case sensitivity problems. Also, camel case sucks with acronyms.

columnID
columnId
columnIDAlternative
columnIdAlternative
RASCScore
RascScore

column_id
column_id_alternative
rasc_score

Also, spaces between words are visually more pleasant than jamming everything together. Absolutely worth whatever perceived pain of typing an underscore there is. Underscores simulate spaces and compound nouns and phrases have spaces in normal, written language. TheOnlyPeopleToTypeLikeThisMayHaveBeenTheRomans.

like image 51
Mark Canlas Avatar answered Sep 22 '22 23:09

Mark Canlas


Whatever you decide to choose, sticking to the same is most important, that is be consistent.

I prefer #2 as this is imo most readable and as mentioned before underscore is ugly and annoying to type. #4 is second best. #3 i like the least, both uppercase and underscore is overkill.

like image 41
Joakim Elofsson Avatar answered Sep 25 '22 23:09

Joakim Elofsson