Sobes.tech
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 Authors table stores a unique author identifier (e.g., author_id).
  • The Books table has a column author_id, which is a foreign key referencing Authors.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.