Designing Your First Relational Database, Gently
Designing a database from a blank page feels hard because there seem to be so many decisions. In practice, a small project needs only a few. This post walks through the process I suggest to beginners, using a tiny book club app as the example.
Step 1: write down the things, not the screens
Forget pages and buttons for a moment. List the *things* your app keeps track of. For a book club:
- members
- books
- meetings
- which books were discussed at which meeting
Each thing you list is a candidate table. Nouns are good candidates; verbs ("discussed") often become link tables later.
Step 2: list facts about each thing
For each table, write the facts you need:
| Table | Facts |
|---|---|
| members | name, email, date joined |
| books | title, author |
| meetings | date, place |
Keep it short. You can always add a column later; removing one that code depends on is harder.
Step 3: give every table a primary key
A primary key is a column whose value identifies one row and never changes. For a beginner project, a simple counting integer is perfect:
CREATE TABLE members (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
email TEXT NOT NULL UNIQUE,
joined_on TEXT NOT NULL
);
UNIQUE on email stops two members sharing one address.
Step 4: link the tables
Ask how things relate. A meeting discusses one or more books, and a book may be discussed at several meetings. That is a many-to-many relationship, so it needs a small table of its own:
CREATE TABLE meeting_books (
meeting_id INTEGER NOT NULL REFERENCES meetings(id),
book_id INTEGER NOT NULL REFERENCES books(id),
PRIMARY KEY (meeting_id, book_id)
);
Each row says "this book was discussed at this meeting". The REFERENCES parts are foreign keys: they point to rows in other tables.
Step 5: test with real questions
Write three questions your app must answer, and check your design can answer them with a query:
- Which books did we discuss in March?
- Which members joined this year?
- Has this book been discussed before?
If a question is awkward to answer, the design may be missing a table or a column. Better to find out now than after you have written the app.
Common first-design mistakes
- One giant table with everything in it, leading to repeated data. See normalisation in three takeaways.
- Lists in a single column, like
books = "Dune, Emma". Make a link table instead. - Using names as keys. People change names; keys should not change.
- No NOT NULL anywhere. Decide which facts are required and say so.
What I would not worry about yet
Indexes beyond keys, performance tuning and fancy data types can wait. A small, clear design that answers your questions is a great first database. When your project grows, you will know which queries matter and can improve from there.
A free learning page for beginners. Practise on a test database, never on real customer data, and check the official documentation for your database version.
Get new pages by email