SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    145
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Auto incremented Prim Key or Composite Key

    Hi there

    I'm wondering what is best practice in the following scenario....

    I need to store 3 columns of data: a Member ID, another Member ID and a Date.
    Each row of data is unique. i.e. there can only be one combination of Member ID's on a given date.

    So, in a situation such as this, is it best to have an auto incremented primary key or make Member ID, the second Memner ID and the Date the primary key?

    It may be worth noting that the table will be queried to return the details of each second member ID where the first member ID is equal to X.

    It may also be worth nothing that multiple INSERTS for the same member combination on the same date may be attempted so the query would either have to use IGNORE or a WHERE depending upon the best way forward.

    Many thanks

  2. #2
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    use a compound primary key, and use IGNORE.
    Check out our new Industry News forum!
    Keep up-to-date with the latest SP news in the Community Crier

    I edit the SitePoint Podcast

  3. #3
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    145
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Done

    Cheers !


Bookmarks

Posting Permissions

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