authorwritesidnamebookborrowsidtitleid name1 Le Guin2 Pratchettmemberloaned_onidnameid title10 Tehanu11 Mort12 Sourceryauthor_id122id name1 Ana2 Benmember_id book_id loaned_on1 11 2026-03-022 11 2026-04-101 12 2026-04-11id991NNM
Back: the ER diagram (entities are boxes, relationships are diamonds)Front: the tables the diagram becomesMovers: entities into tables, the key into a foreign key, a refused loanAt the back: the ER diagram of a small library, with three entities (author, book, member) and two relationships (writes, borrows). In front: the tables the diagram turns into. Each entity becomes a table with its key as the primary key; the one-to-many writes becomes a foreign key, book.author_id; the many-to-many borrows becomes a table of its own, loan. The foreign keys then refuse a loan for book 99, and a join follows them back to answer who borrowed what. This figure uses Chen’s original notation: boxes, diamonds, and 1, N and M on the lines. Many tools draw “crow’s foot” lines instead; the ideas are the same.

The ER diagram

  1. An entity is a kind of thing you keep facts about. Read the brief and pick out its nouns: authors write books, members borrow books. That gives three entities: author, book and member.

From diagram to tables

The design at work

What happens

;; step 1/10 · entities
the brief:
  Authors write books. Members borrow books, each loan on a date.

nouns -> entities (drawn as boxes)
  author
  book
  member

an entity is a kind of thing, not one thing:
  "book" stands for every book the library owns

Real books can have several authors. Then writes would be many-to-many too, and it would get its own table (book_author) just like loan. The figure keeps one author per book so you can see both kinds. A foreign key does not create an index on its own column in PostgreSQL. Joins and deletes that look up book.author_id or loan.book_id are faster if you add one (CREATE INDEX ON loan (book_id)). The primary key already gives loan an index that starts with member_id.