The main table contains the parent records, those records that define the root records, such as the "messages" in this example.
External tables contain child records, those records that are associated with parent records accordingly.
So, “comment” is a child of “post”, therefore: “Post” is the parent (main in your example) “Comment” is a child (foreign in your example)
PostId values must be unique in the Post table ... but the same PostId value can appear several times in the comment table (because there can be many comments for one message, comment 1 for message 1, comment 2 for message 1).
A 1-1 relationship is when two objects are peer-to-peer. that is, the Student can be a user, and the User can be a Student. Two students cannot be the same user. Two users cannot be the same student. Therefore, User-Student is 1-1.
From many to many relationships, it is best to model a table between them.
Book (main)
Author (primary)
Author's books (comparison)
BookId is unique in books (only one book can have a specific identifier)
AuthorId is unique to authors (only one author can have a specific identifier)
BookBook BookBook has both BookId and AuthorId columns, as well as maps for authors.
This relationship is modeled because the author may have written many books, and because a particular book may have many authors.
source share