> Ah - I've got myself into the habit of always having an id column for every
> table, so that I know I can always refer to each individual row easily.

that, indeed, is the purpose of a primary key

however, the primary key need not be a surrogate key

in the case of a relationship table, the best primary key is the pair of foreign
keys

thus,

    create table userdepts
    ( user_id integer not null
    , foreign key (user_id) references users (user_id)
    , dept_id integer not null
    , foreign key (dept_id) references depts (dept_id)
    , primary key (user_id,dept_id)
    );

some database developers who declare a surrogate id as the primary key of such a
table will forget to declare an additional unique constraint on the pair of
keys, thus opening the door to the same user being assigned to the same
department more than once -- the compound natural primary key avoids the need
for this additional constraint because it is, by definition, unique

rudy


____ • The WDVL Discussion List from WDVL.COM • ____
To Join wdvltalk, Send An Email To: mailto:[EMAIL PROTECTED] or
use the web interface http://e-newsletters.internet.com/discussionlists.html/
       Send Your Posts To: [email protected]
To change subscription settings, add a password or view the web interface:
http://intm-dl.sparklist.com/read/?forum=wdvltalk

________________  http://www.wdvl.com  _______________________

You are currently subscribed to wdvltalk as: [email protected]
To unsubscribe send a blank email to [EMAIL PROTECTED]
To unsubscribe via postal mail, please contact us at:
Jupitermedia Corp.
Attn: Discussion List Management
475 Park Avenue South
New York, NY 10016

Please include the email address which you have been contacted with.

Reply via email to