table composite primary key and one to many relationship

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • emilyjac
    New Member
    • May 2012
    • 4

    table composite primary key and one to many relationship

    Hi.

    I have a junction table with a composite primary key (ie. two field are used to define the primary key). I need link a third table to the junction table in a one to many relationship. In the attached photo Click image for larger version

Name:	relation_probleme.jpg
Views:	1
Size:	27.3 KB
ID:	5417908, the table without any relations should be on the "many" side and the junction table on the "one" side.
    [imgnothumb]http://bytes.com/attachments/attachment/6372d1336683014/relation_proble me.jpg[/imgnothumb]

    The idea is that there are a many "elements" elements linked to many "inspection s" and vica-versa. for each pair element-inspection i want to attribute a "condition" , in turn this one "conditon" can be linked to many "recommandation s".

    I have considered using a single field primary key in the junction table called id_cond, but I don't want to do it like this because i don't want to the possibility of an element being attributed multiple conditions for the same inspection.

    So how do I do it?
    Last edited by NeoPa; May 10 '12, 10:39 PM. Reason: Made pic viewable.
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32653

    #2
    You can link [tbl_cond_recomm and] by adding both fields of the composite PK of [tbl_condition_e le] to it.

    However, you can also assign a single-field, unique PK to [tbl_condition_e le] if you choose (and there are reasons why it would be advisable). Having a PK doesn't stop any other indices from being set up as mandatorily unique.

    Comment

    • emilyjac
      New Member
      • May 2012
      • 4

      #3
      Hello. Thank you for the info about being able to have unique indices that aren't primary keys. I used it in a slightly different way than you suggested. I made a triple field primary key and made one of those fields unique (Click image for larger version

Name:	Noname.jpg
Views:	1
Size:	34.5 KB
ID:	5413369). Does anyone have any feed-back about which of the solutions presented is best, and why?
      [imgnothumb]http://bytes.com/attachments/attachment/6373d1336699291/noname.jpg[/imgnothumb]
      Last edited by NeoPa; May 11 '12, 02:25 AM. Reason: Made pic viewable.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32653

        #4
        That's not a good idea Emily. Never make an index more than it needs to be. [id_cond] can (should) be the PK and a compound index including [id_element] & [id_inspec] can be set up as unique. What more you may need/require is down to what you require the design to do for you.

        Comment

        Working...