Could use some help understanding how to create a Foreign Key Constraint with two parent tables - one of which has a Composite UK that includes a DateTime field.
The first “parent” table is normal and looks like this…
member (Reviewer)
- id (PK)
- email (UK)
and so on...
The second “parent” table is trickier, because it has a Composite UK like this…
article_comment
- id (PK)
- article_id (UK1)(FK)
- member_id (UK2)(FK) **Commenter
- created_on (UK3)
My “child” junction table looks like this…
article_comment_review
- id (PK)
- article_id (UK1)(FK)
- commenter_id (UK2)(FK)
- comment_created_on (UK3)(FK)
- reviewer_id (UK4)(FK)
- rating
While I could join this article_comment_review to the PK of each Parent table above, it wouldn’t be very descriptive, and so I would like to use the Composite UK from the second “parent” table.
Here is where I am confused…
When I build the Foreign Key Constraint for article_comment_review, how do I link FROM article_comment_review.comment_created_on TO article_comment.created_on?? :-/
To build a link between the Parent and Child tables in the Foreign Key relationship, phpMyAdmin requires that an Index exists on each field in the Foreign Key. So that means I would need to place an Index on the article_comment_review.comment_created_on field…
In the Parent table, only the combination of “article_id” + “member_id” + “created_on” make a Comment unique. So it seems to me that I need the following links…
article_comment_review.article_id ---> article_comment.article_id
article_comment_review.commenter_id ---> article_comment.member_id
article_comment_review.comment_created_on ---> article_comment.created_on
article_comment_review.reviewer_id ---> member (Reviewer).id
But how can I put an Index on a DateTime column - especially when that column might have multiple instances of the same time-stamp??
Follow me?
What do I do???
Sincerely,
Debbie