The example library
Most examples in this documentation use the same small database: a library with authors, books, members, and loans. Keeping one familiar set of tables makes it easier to focus on the concept each page is teaching.
The tables
Section titled “The tables”| Table | Columns |
|---|---|
authors | author_id (serial, primary key), name (text), birth_year (int) |
books | book_id (serial, primary key), title (text), author_id (int → authors), published (int), isbn (text, unique) |
members | member_id (serial, primary key), name (text), joined (date) |
loans | loan_id (serial, primary key), book_id (int → books), member_id (int → members), loaned_on (date), returned_on (date) |
The relationships
Section titled “The relationships”- An author has many books.
books.author_idpoints atauthors.author_id— a one-to-many relationship. - Members borrow books. Each row in
loansties one book to one member, soloansconnectsbooksandmembers— a many-to-many relationship expressed through a bridging table.
You will build these tables and relationships step by step in Build the library. Individual reference pages use whichever part of this schema illustrates the command at hand.