NYCPHP Meetup

NYPHP.org

[nycphp-talk] Database, table, and column naming schemes

tedd tedd at sperling.com
Tue Oct 6 11:41:52 EDT 2009


At 4:06 AM -0700 10/6/09, Kristina Anderson wrote:
>  > >
>>  >
>>  > What would you call that many:many table?
>>  >
>>  > Surely, not account_user, and not user_account
>>
>>  Why not AccountUser? 
>>
>  > Some PHP frameworks do indeed follow that convention.
>
>AccountUser or account_user would definitely be the most commonly used
>conventions, but if you feel that you want to make it more obvious that
>the relationships are many-to-many, you can use AccountsUsers or some
>version of a pluralized name...the equally important thing in my view
>is to make sure you're keeping your DB schema up to date including
>table descriptions in sufficient detail. 
>
>- Kristina

I second the splendid advice given by Kristina. I only add that you 
develop a convention that works for you and that you are consistent 
with it.

As an alternative to using parts of other table names to construct a 
new table name, this might help: Typically when one is creating a 
many:many record it's to record an instance of a relationship between 
two different items -- and -- with considered thought you usually can 
create a descriptive name for that relationship. For example, if you 
are connecting students to classes, then a table name like 
"registrations" makes sense. If you are connecting an audience to 
plays, then a table name like "tickets" makes sense.

Look for a reason why a many:many record should exist, then try to 
find a descriptive name for it.

If you can't, then closely look at the tables you have created for 
your items and ask yourself if the tables are accurate descriptions 
of their contents?

In your case, you have "users" and "accounts". I can guess that users 
are people, but I'm not sure what "accounts" are.  But, for example, 
if the accounts were different types of insurances, then I might 
create a many:many table called "policies" where I would connect 
users to accounts. If that were the case, I might change the 
"accounts" table name to be more specific like "insurance_types". Do 
you see how this is done?

I find the best way to solve this is to think about it before going 
to sleep. Then after I wake, I usually have a solution.

Cheers,

tedd

-- 
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com



More information about the talk mailing list