Results 1 to 3 of 3

Thread: composite key

  1. #1
    Join Date
    Jun 2002
    Posts
    63

    Lightbulb Unanswered: composite key

    Hi i'm making a table that has a composite key.

    TABLE
    - someid CK FK
    - number CK
    - somefield

    So the composite key will look like:

    1 1
    1 2
    2 1
    2 2
    2 3
    3 1
    4 1

    blah blah blah

    How do i make the field 'number' UNIQUE, but ONLY where the filed someid is the same? if you see what I mean???

    Thanks

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    that's easy, give the CK a unique constraint

    thus, you can have

    3 15
    3 16
    4 27
    4 28
    5 15
    5 16

    5 15 and 5 16 are okay, because 15 and 16 are allowed to repeat within the context of the composite unique constraint, but you cannot add 3 15 again, nor 4 27

    if you define the CK as a PK, it automatically gets a unique constraint

    rudy
    http://r937.com

  3. #3
    Join Date
    Jun 2002
    Posts
    63
    There's always someone who has to answer all the questions, isn't there! lol

    Thanks, I thought that would have made it unique throughout the table.


Posting Permissions

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