Design Practice: Event Bookings
Two tables, one link.
Helen's events are popular. Now customers want to book seats. One event has many customers. And one customer can book many events. How should we store that?

- Customers book seats
- One event, many customers
- One customer, many events
Many to many
This is called a many to many relationship. You can't put a list of customers inside an event row. That breaks rule one. Instead, you add a linking table. Each row in it says, this customer booked this event. Order items works exactly the same way, linking orders and books.
The design in SQL
Here's the design. Events, with rules on the title, date, and seats. And bookings, the linking table. Its two foreign keys point to events and customers. And its primary key is the pair of them together, so nobody can book the same event twice. Run it. Both tables now exist.
CREATE TABLE events (
event_id INTEGER PRIMARY KEY,
title TEXT NOT NULL,
event_date TEXT NOT NULL,
seats INTEGER CHECK (seats > 0)
);
CREATE TABLE bookings (
event_id INTEGER REFERENCES events (event_id),
customer_id INTEGER REFERENCES customers (customer_id),
booked_on TEXT,
PRIMARY KEY (event_id, customer_id)
);
SELECT name FROM sqlite_master
WHERE name IN ('events', 'bookings');โโโโโโโโโโโโ โ name โ โโโโโโโโโโโโค โ events โ โ bookings โ โโโโโโโโโโโโ
Summary
Many to many relationships need a linking table, with two foreign keys. You just designed a real database. Next, how SQL differs between database products.
Key takeaways- Many to many
- A linking table
- Composite primary key