Course Resources

Search

Search IconIcon to open search

Last updated Nov 17, 2024

# Introduction to One-to-Many Relationships

# What is a One-to-Many Relationship?

In relational databases, a one-to-many relationship is the most fundamental type of relationship. This relationship exists when a record in one table can be associated with multiple records in another table.

For example, consider a database of a bookstore. Here, we have two tables: Authors and Books. An author can write multiple books, but each book is written by only one author. This is a classic one-to-many relationship.

# Authors Table:

AuthorIDAuthorName
1J.K. Rowling
2George Orwell
3Leo Tolstoy

# Books Table:

BookIDTitleAuthorID
101Harry Potter1
10219842
103Animal Farm2
104War and Peace3
105Anna Karenina3

# Understanding the Direction of the Relationship

It’s important to understand exactly why this is a one-to-many relationship. Why can we can have many books per author but only one author per book? The structure of the table tells us this is how the relationship must work. Here’s how:

# Terminology: Primary Keys and Foreign Keys

# Primary Key

# Foreign Key

# Lessons