pooya mahmoodi
pooya mahmoodi

Reputation: 93

Understanding the One-Many relation

I need help understanding of One-to-Many relationships between two tables in SQL Server.

Suppose there are two tables: an Author table (AuthorId, AuthorName) and a Book table (BookId, BookName). Also suppose each Book just has one Author , but an Author can have many Books.

If there were a field on the Author table that would keep a list of Book (written by this author) my problem would be solved and I would understand this. But this isn't right.

So how is the list of Books by each Author determined with a one-to-many relationship? Where are the BookId values of an Author kept?

Upvotes: 0

Views: 45

Answers (2)

Youfah Mizzum
Youfah Mizzum

Reputation: 19

The book table will need another column called AuthorID. i.e

author table (AuthorId, AuthorName) and a book table (BookId, BookName, AuthorID)

Upvotes: 1

Joel Coehoorn
Joel Coehoorn

Reputation: 416059

How the list of books of each author is determined by a one-to-many relationship? Where the address of this books id is kept?

Put an AuthorID field in the Books table. To know the list of books an author has written, you SELECT from the Books table based on that AuthorID. If you also want to know, for example, the Author's name in the same query, you use a JOIN.

Upvotes: 3

Related Questions