Search Postgresql Archives

Surrogate VS natural keys

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



OK so which is the "correct" way to do it?

E.g., Say I have a table with users, and a table with clubs, and a table
that links them. Each user can be in more than one club and each club
has more than one member. Standard M:M relationship. Which link table is
the "right" way to do it?

This:

CREATE TABLE (
    userid INTEGER NOT NULL REFERENCES users,
    clubid INTEGER NOT NULL REFERENCES clubs,
    PRIMARY KEY (userid, clubid)
);

Or this:

CREATE TABLE (
    id SERIAL PRIMARY KEY,
    userid INTEGER NOT NULL REFERENCES users,
    clubid INTEGER NOT NULL REFERENCES clubs
);

I've always favored natural keys (the first option) as it just seems to
me a more natural and semantic representation of the data, however I
often get app designers complaining about it being more complex or
something.

Comments?


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux