NYCPHP Meetup

NYPHP.org

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

Dan Cech dcech at phpwerx.net
Tue Oct 6 12:43:25 EDT 2009


Kristina Anderson wrote:
> Exactly, the table would contain probably nothing more than a primary 
> key autonumber field, the user id and account id in each row.

Why do you need a separate primary key?  The relationship is defined by
user id and account id.

CREATE TABLE some_rel (
  user_id int(11) not null,
  account_id int(11) not null,
  some_attribute varchar(255),
  PRIMARY KEY (user_id,account_id)
);

I added the attribute column to illustrate that you can still identify
the row like:

SELECT some_attribute FROM some_rel WHERE user_id=X AND account_id=Y

HTH,

Dan



More information about the talk mailing list