Results 1 to 8 of 8
  1. #1
    Join Date
    Aug 2002
    Posts
    121

    Question Unanswered: Primary / Foreign Keys

    Hello,
    I have a table, RESULT_TABLE, with numerous fields. Four of these fields correspond to a primary key value in a look-up table. Specifically, each of these 4 fields are diagnosis codes, all of which are the primary key values of another table, the DIAG_TABLE. Is it necessary to apply a foreign key constraint to each of these 4 fields in the RESULT_TABLE?

  2. #2
    Join Date
    Jul 2003
    Posts
    2,296
    are you saying it is impossible to have duplicate entries of 4 diagnosis codes?

    perhaps you want to make sure that each of the 4 independent
    dianosis-code entries is a valid code that exists in the DIAG_TABLE?
    - The_Duck
    you can lead someone to something but they will never learn anything ...

  3. #3
    Join Date
    Sep 2004
    Location
    London, UK
    Posts
    565
    Yes, each of the "code" columns needs its own FK constraint.

  4. #4
    Join Date
    Aug 2002
    Posts
    121
    Quote Originally Posted by The_Duck
    are you saying it is impossible to have duplicate entries of 4 diagnosis codes?

    perhaps you want to make sure that each of the 4 independent
    dianosis-code entries is a valid code that exists in the DIAG_TABLE?
    Yes, there can be duplicate entries of the Dx_codes in the RESULTS_TABLE.

  5. #5
    Join Date
    Aug 2002
    Posts
    121
    Quote Originally Posted by WilliamR
    Yes, each of the "code" columns needs its own FK constraint.
    Thanks William

  6. #6
    Join Date
    Jul 2003
    Posts
    2,296
    Quote Originally Posted by tmalone
    Yes, there can be duplicate entries of the Dx_codes in the RESULTS_TABLE.
    so no PK then unless I am reading this incorrectly.
    the combination of the 4 is not unique?
    - The_Duck
    you can lead someone to something but they will never learn anything ...

  7. #7
    Join Date
    Sep 2004
    Location
    London, UK
    Posts
    565
    As I understand it DIAG_TABLE has a PK on one column, and RESULTS_TABLE has four separate diagnosis code columns each of which should reference it.

    btw I hope those aren't the real table names

  8. #8
    Join Date
    Aug 2002
    Posts
    121
    Quote Originally Posted by WilliamR
    As I understand it DIAG_TABLE has a PK on one column, and RESULTS_TABLE has four separate diagnosis code columns each of which should reference it.
    Yes, that's right. Thanks

Posting Permissions

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