Note that there are some explanatory texts on larger screens.

plurals
  1. POOne to Many Database Relationship
    primarykey
    data
    text
    <p>Guys I would really appreciate it if someone could help me with this. I have a schema with 4 tables relevant to this question Books, Groups, ReadingList, Comments. A user of the system can join a group and add books to that group's reading list. A group's book list is represented by the table ReadingList:</p> <pre><code>ReadingList ------------- Id (auto_increment) ReadingListID BookID (pk) GroupID (pk) </code></pre> <p>BookID and GroupID are set up as a composite primary key to ensure no book can appear on a groups reading list twice. Both these fields have a fk defined to the relevant table Books/Groups. Now my problem comes when trying to set up a relationship between the Comments table and the ReadingList. The theory is that each unique entry in the ReadingList can have many comments (1..*) so basically one book on a groups reading list can have many comments associated with in. The Comments table looks like this:</p> <pre><code>Comments ----------- Id (pk, auto_increment) ReadingListID UserName Comment TimeStamp </code></pre> <p>My logic is that a fk be set up from Comments (ReadingListID) to ReadingList (ReadingListID) but I am clearly flawed as I get a 'no primary or candidate keys in referenced table' error.</p> <p>I have tried a variety of things like making ReadingListID &amp; Id in the Comments table a composite key and making ReadingListID a pk in the ReadingList table etc, but I just can't get my head round this. Please let me know if I haven't been clear enough.</p> <p>Many thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload