Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2004
    Location
    India
    Posts
    4

    Unanswered: Composite Primary Key

    WHile designing a Database should one go for composite Primary Keys.
    Or what are the Pros and Corns of Composite Primary Keys

    Thanx

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    No, you should only use IDENTITY columns....
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  3. #3
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Just kidding....

    http://www.datamodel.org/

    Define what it takes to uniquely identify a row in a table, no matter how many columns...

    And then establish relationships between these objects...

    Then you'll have a logical model...

    How you physically implement is another story...but start there...
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  4. #4
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Come on...I thought that was funny....


    ..."but what if I need to change the name of a City? Like when New Amsterdam became New York City...IDENTITY would be good there, no?"
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    identity? heh, yes, i thought that was funny

    and the delivery was excellent

    create table constants
    ( id smallint not null primary key
    , name varchar(5) not null
    , constant double precision not null
    )
    insert into constants (name,constant)
    values ('pi', 3.141592653589793)

    always reference a row by its primary key

    which for pi is 1 in the above case, since that was the first constant entered into the table

    so whatever id number it gets when you insert that row in your table, just remember the id number and always use it in your sql

    the benefit of this is that your sql will not have to change in case pi ever changes its name or value
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  6. #6
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,800
    Provided Answers: 11
    http://www.straightdope.com/classics/a3_341.html

    A classic I had to look up once more.....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •