views:

497

answers:

8

I've been reading a couple of questions/answers on StackOverflow trying to find the 'best', or should I say must accepted way, to name tables on a Database.

Most of the developers tend to name the tables depending on the language that requires the database (JAVA, .NET, PHP, etc). However I just feel this isn't right.

The way I've been naming tables till now is doing something like:

doctorsMain
doctorsProfiles
doctorsPatients
patientsMain
patientsProfiles
patientsAntecedents

The things I'm concerned are:

  • Legibility
  • Quick identifying of the module the table is from (doctors||patients)
  • Easy to understand, to prevent confusions.

I would like to read any opinions regarding naming conventions. Thank you.

+3  A: 

I typically use Pascal case and the entities are singular:

DoctorMain
DoctorProfile
DoctorPatient
etc...

It mimics the naming conventions for classes in my application keeping everything pretty neat, clean, consistent, and easy to understand for everybody.

Justin Niessner
Don't you mean Pascal case?
ScottE
Yes...yes I do. I'm a little foggy this morning. Making the edit...thanks.
Justin Niessner
+16  A: 

Being consistent is far more important that what particular scheme you use.

David Oneill
In other words, yes, well done, you've identified some consistent schemes. Get on with it!
Phil H
+1 for the comment. Also, on a side note to the current naming scheme PascalCase is better, specially if you don't use Aliases for the SQL Queries. This way you can just use camelcase on the table column names and Pascal Case on the Table Names.
kuroir
A: 

Unfortunately there is no "best" answer to this question. As @David stated consistency is far more important than the naming convention.

Kane
+3  A: 

I use underscores. I did an Oracle project some years ago, and it seemed that Oracle forced all my object names to upper case, which kind of blows any casing scheme. I am not really an Oracle guy, so maybe there was a way around this that I wasn't aware of, but it made me use underscores and I have never gone back.

Ray
+1  A: 

I tend to agree with the people who say it depends on the conventions of language you're using (e.g. PascalCase for C# and snake_case for Ruby).

Never camelCase, though.

Coder 42
A: 

there's wide variability on how to separate words, so there you'll have to pick whatever you like better; but at the same time, it seems there's near consensus that the table name should be singular.

Javier
+1  A: 

Case insensitive nature of SQL supports Underscores_Scheme. Modern software however supports any kind of naming scheme. However sometimes some nasty bugs, errors or human factor can lead to UPPERCASINGEVERYTHING so that those, who selected both Pascal_Case and Underscore_Case scheme live with all their nerves in good place.

terR0Q
A: 

An aggregation of most of the above:

  • don't rely on case in the database
  • don't consider the case or separator part of the name - just the words
  • do use whatever separator or case is the standard for your language

Then you can easily translate (even automatically) names between environments.

But I'd add another consideration: you may find that there are other factors when you move from a class in your app to a table in your database: the database object has views, triggers, stored procs, indexes, constraints, etc - that also need names. So for example, you may find yourself only accessing tables via views that are typically just a simple "select * from foo". These may be identified as the table name with just a suffix of '_v' or you could put them in a different schema. The purpose for such a simple abstraction layer is that it can be expanded when necessary to allow changes in one environment to avoid impacting the other. This wouldn't break the above naming suggestions - just a few more things to account for.

KenFar