--- title: Build the library description: Build the example library database step by step — tables, a relationship, and some rows. sidebar: order: 1 --- :::note[Draft] This guide is an early draft. The walkthrough is correct, but the wording and pacing will be refined for teaching before the docs are published. ::: This guide builds the [example library](/getting-started/example-library/) from scratch in simple mode: two tables, a relationship between them, and a few rows. By the end you will have used the create → add column → relate → insert → query loop end to end. ## 1. Create the authors table ```text create table authors with pk author_id(serial) add column to authors: name (text) add column to authors: birth_year (int) ``` ## 2. Create the books table ```text create table books with pk book_id(serial) add column to books: title (text) add column to books: author_id (int) add column to books: published (int) ``` ## 3. Relate books to authors An author has many books, so `books.author_id` should point at `authors.author_id`. Declare that one-to-many relationship: ```text add 1:n relationship from authors.author_id to books.author_id ``` The relationship reads parent-to-child: **from** the `authors` side **to** the `books` side. ## 4. Add some rows `author_id` and `book_id` are `serial`, so they fill themselves in: ```text insert into authors (name, birth_year) values ('Ada Lovelace', 1815) insert into authors (name, birth_year) values ('Alan Turing', 1912) insert into books (title, author_id, published) values ('Notes on the Analytical Engine', 1, 1843) ``` ## 5. Look at your data ```text show data authors show data books ``` ## Where to go next - Add the `members` and `loans` tables the same way to model borrowing — a many-to-many relationship through `loans`. - Try the same steps in advanced mode to see the SQL form of each command. - Look up any command in detail in the Reference section.