Middle
How is a one-to-many physical relationship stored in a database? What will be in the tables?
sobes.tech AI
Answer from AI
In a database, a one-to-many relationship is implemented using a foreign key in the table that represents the "many" side.
For example, there are two tables: Authors and Books. One author can have many books, but each book belongs to one author.
- The
Authorstable stores a unique author identifier (e.g.,author_id). - The
Bookstable has a columnauthor_id, which is a foreign key referencingAuthors.author_id.
Thus, each record in Books points to one author, ensuring a one-to-many relationship.
Table examples:
| Authors | Books |
|---|---|
| author_id (PK) | book_id (PK) |
| name | title |
| author_id (FK) |
Where PK is the primary key, and FK is the foreign key.