SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Composite Keys

  1. #1
    SitePoint Enthusiast ParfaitMacaron's Avatar
    Join Date
    Mar 2013
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Composite Keys

    If I have 6 fields in a table, where one of them is the id of "x" table so that it becomes the primary key e.g. "x_id" and then have a, b, c, d fields which are also id fields (a_id, b_id, c_id, d_id) to form a composite key, is this ok?

    And the next question is how would I code up the MySQL?

    Is it allowed to join a composite key field e.g. "a_id" (foreign key) in the child table to the primary key "a_id" of the parent table in a one-to-many relationship?

    Thanks!

  2. #2
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,089
    Mentioned
    55 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ParfaitMacaron View Post
    If I have 6 fields in a table, where one of them is the id of "x" table so that it becomes the primary key e.g. "x_id" and then have a, b, c, d fields which are also id fields (a_id, b_id, c_id, d_id) to form a composite key, is this ok?

    And the next question is how would I code up the MySQL?

    Is it allowed to join a composite key field e.g. "a_id" (foreign key) in the child table to the primary key "a_id" of the parent table in a one-to-many relationship?

    Thanks!
    May I ask the relationship you plan on implementing? 6 keys seems to me like theres something a little excessive going on

  3. #3
    SitePoint Enthusiast ParfaitMacaron's Avatar
    Join Date
    Mar 2013
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by K. Wolfe View Post
    May I ask the relationship you plan on implementing? 6 keys seems to me like theres something a little excessive going on
    It's a one-to-many relationship. There's only 4 keys now.

  4. #4
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,089
    Mentioned
    55 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ParfaitMacaron View Post
    It's a one-to-many relationship. There's only 4 keys now.
    Well you see what I mean? You're down to 4 rather than 6. Can you explain the relationship? Column names and what they are / mean?


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
  •