Bonus: Database Design for a Flight Booking System
What's in this guide
This guide goes with my YouTube video on designing a database for a Flight Booking website. In it, you'll find:
- The Entity Relationship Diagram for a flight booking system from the video
- An explanation of the purpose of each table and column, with sample data
- An SQL script to create each of these tables
Prefer a PDF? You can download the PDF version of this guide.
Entity Relationship Diagram
Here's the ERD for this database:
The Tables
This section explains each of the 10 tables and their columns.
country
A lookup table with a list of countries. Used for airports, which are used for arrivals and destinations.
| Column | Description | Sample Data |
|---|---|---|
| id | Primary key. A unique identifier for the row. | 1, 2, 3 |
| country_name | The name of the country in the table | France, England, Australia |
city
A lookup table for the different cities that are within a country.
| Column | Description | Sample Data |
|---|---|---|
| id | Primary key. A unique identifier for the row. | 1, 2, 3 |
| city_name | The name of the city. Shown in the lookups for airports or destinations. | London, Paris |
| country_id | A foreign key to the country table. |
airport
A lookup table for the airports that a flight can arrive at or depart from.
| Column | Description | Sample Data |
|---|---|---|
| id | Primary key. A unique identifier for the row. | 1, 2, 3 |
| city_id | A foreign key to the city table. | |
| code | A short code that represents the airport in the | LAX |
| Learn how to design an effective database & create it with SQL | 2 real world | |
| name | The name of the airport. Shown on the list of airports when searching for flights. | London Heathrow, Charles de Gaulle |
airline
A table that contains all of the airline companies that offer flights around the world.
| Column | Description | Sample Data |
|---|---|---|
| id | Primary key. A unique identifier for the row. | 1, 2, 3 |
| name | The name of the airline company. | Air France, Qatar Airways, British Airways |
booking_type
A record that represents the type of a booking, such as Return or One-Way.
| Column | Description | Sample Data |
|---|---|---|
| id | Primary key. A unique identifier for the row. | 1, 2, 3 |
| type_name | A readable name of the type of booking | Return, One-way, Multi-city |
booking_class
A lookup table for the class of ticket that can be bought.
| Column | Description | Sample Data |
|---|---|---|
| id | Primary key. A unique identifier for the row. | 1, 2, 3 |
| class_name | The name of the flight class that can be booked | Economy, Premium Economy |
| Learn how to design an effective database & create it with SQL | 3 | |
| item_order | A number that indicates how the list of values should be ordered on the screen | 10, 20, 30, 40 |
booking
A record of the booking made for a flight.
| Column | Description | Sample Data |
|---|---|---|
| id | Primary key. A unique identifier for the row. | 1, 2, 3 |
| booking_type_id | A foreign key to the booking_type table. | |
| class_id | A foreign key to the booking_class table. |
booking_class_supply
A record of the number of seats available for each flight and booking class, which allows you to check flight availability.
| Column | Description | Sample Data |
|---|---|---|
| booking_class_id | A foreign key to the booking_class table. | |
| flight_supply_id | A foreign key to the flight_supply table. | |
| no_seats | The number of seats available for this flight and for this class of flight. | 200, 16 |
| price_gbp | The price of a ticket on this flight for this class. The price is in GBP. | 100, 96, 1500 |
booked_flight
A record of the flight that has been booked, because a booking can contain multiple flights.
| Column | Description | Sample Data |
|---|---|---|
| id | Primary key. A unique identifier for the row. | 1, 2, 3 |
| Learn how to design an effective database & create it with SQL | 4 | |
| booking_id | A foreign key to the booking table. | |
| flight_supply_id | A foreign key to the flight_supply table. |
flight_supply
A list of flights that are available to be booked.
| Column | Description | Sample Data |
|---|---|---|
| id | Primary key. A unique identifier for the row. | 1, 2, 3 |
| flight_no | A short code that represents the specific flight. This is shown on boarding passes and departure gate signs. | BA123, QF780 |
| airline_id | A foreign key to the airline table. | |
| departure_datetime | The date and time that the flight departs from the airport | 27 Jun 2025 9:15 AM |
| departing_airport_id | A foreign key to the airport table, representing the airport that the flight departs from. | |
| arriving_airport_id | A foreign key to the airport table, representing the airport that the flight arrives at. | |
| Learn how to design an effective database & create it with SQL | 5 |
SQL Script
Here is the SQL code to create the tables for this database.
The script is written for MySQL, but it can easily be modified to work on your preferred database vendor by changing the data types and removing the IF EXISTS (if your database doesn't support it).
1CREATE DATABASE flights;
2
3USE flights;
4
5CREATE TABLE country (
6 id INTEGER,
7 country_name VARCHAR(200),
8 CONSTRAINT pk_country PRIMARY KEY (id)
9);
10
11CREATE TABLE city (
12 id INTEGER,
13 city_name VARCHAR(100),
14 country_id INTEGER,
15 CONSTRAINT pk_city PRIMARY KEY (id),
16 CONSTRAINT fk_city_country FOREIGN KEY (country_id) REFERENCES country (id)
17);
18
19INSERT INTO country (id, country_name) VALUES
20(1, 'United Kingdom'),
21(2, 'France');
22INSERT INTO city (id, city_name, country_id) VALUES
23(1, 'London', 1),
24(2, 'Paris', 2);
25
26CREATE TABLE airport (
27 id INTEGER,
28 city_id INTEGER,
29 code VARCHAR(5),
30 name VARCHAR(100),
31 CONSTRAINT pk_airport PRIMARY KEY (id),
32 CONSTRAINT fk_airport_city FOREIGN KEY (city_id) REFERENCES city (id)
33);
34
35INSERT INTO airport (id, city_id, code, name) VALUES
36(1, 1, 'LHR','Heathrow'),
37(2, 2, 'CDG', 'Charles de Gaulle'),
38(3, 1, 'LGW', 'Gatwick'),
39(4, 1, 'STN', 'Stanstead'),
40(5, 2, 'ORY', 'Orly'),
41(6, 2, 'BVA', 'Beauvais');
42
43CREATE TABLE booking_type (
44 id INTEGER,
45 type_name VARCHAR(50),
46 CONSTRAINT pk_bookingtype PRIMARY KEY (id)
47);
48
49CREATE TABLE booking (
50 id INTEGER,
51 booking_type_id INTEGER,
52 booking_class_id INTEGER,
53 CONSTRAINT pk_booking PRIMARY KEY (id),
54 CONSTRAINT fk_booking_type FOREIGN KEY (booking_type_id) REFERENCES booking_type (id),
55 CONSTRAINT fk_booking_class FOREIGN KEY (booking_class_id) REFERENCES booking (id)
56);
57
58INSERT INTO booking_type (id, type_name) VALUES
59(1, 'Return'),
60(2, 'One-way'),
61(3, 'Multi-city');
62/* SQL 11 */
63
64CREATE TABLE booking_class (
65 id INTEGER,
66 class_name VARCHAR(20),
67 item_order INTEGER,
68 CONSTRAINT pk_bookingclass PRIMARY KEY (id)
69);
70
71INSERT INTO booking_class (id, class_name, item_order) VALUES
72(1, 'Economy', 10),
73(2, 'Premium Economy', 20),
74(3, 'Business', 30),
75(4, 'First Class', 40);
76
77CREATE TABLE airline (
78 id INTEGER,
79 name VARCHAR(100),
80 CONSTRAINT pk_airline PRIMARY KEY (id)
81);
82
83CREATE TABLE flight_supply (
84 id INTEGER,
85 flight_no VARCHAR(5),
86 airline_id INTEGER,
87 departure_datetime DATETIME,
88 departing_airport_id INTEGER,
89 arriving_airport_id INTEGER,
90 CONSTRAINT pk_flightsupply PRIMARY KEY (id),
91 CONSTRAINT fk_flightsupply_airline FOREIGN KEY (airline_id) REFERENCES airline (id),
92 CONSTRAINT fk_flightsupply_depairport FOREIGN KEY (departing_airport_id) REFERENCES airport (id),
93 CONSTRAINT fk_flightsupply_arrairport FOREIGN KEY (arriving_airport_id) REFERENCES airport (id)
94);
95
96CREATE TABLE booked_flight (
97 id INTEGER,
98 booking_id INTEGER,
99 flight_supply_id INTEGER,
100 CONSTRAINT pk_bookedflight PRIMARY KEY (id),
101 CONSTRAINT fk_bookedflight_booking FOREIGN KEY (booking_id) REFERENCES booking (id),
102 CONSTRAINT fk_bookedflight_flightsupply FOREIGN KEY (flight_supply_id) REFERENCES flight_supply (id)
103);
104
105CREATE TABLE booking_class_supply (
106 booking_class_id INTEGER,
107 flight_supply_id INTEGER,
108 no_seats INTEGER,
109 price_gbp DECIMAL(10, 2),
110 CONSTRAINT fk_bts_classtype FOREIGN KEY (booking_class_id) REFERENCES booking_class (id),
111 CONSTRAINT fk_bts_flightsupply FOREIGN KEY (flight_supply_id) REFERENCES flight_supply (id)
112);
113
114INSERT INTO airline(id, name) VALUES
115(1, 'Air France'),
116(2, 'British Airways');
117INSERT INTO flight_supply (id, flight_no, airline_id,
118departure_datetime, departing_airport_id, arriving_airport_id) VALUES
119(1, 'AF545', 1, '2025-03-18 14:45', 1, 2),
120(2, 'AF971', 1, '2025-03-18 06:20', 1, 2),
121(3, 'AF343', 1, '2025-03-18 11:30', 1, 2),
122(4, 'AF545', 1, '2025-03-18 19:35', 1, 2),
123(5, 'AF696', 1, '2025-03-18 17:35', 1, 2),
124(6, 'BA935', 2, '2025-03-18 07:15', 1, 2),
125(7, 'BA426', 2, '2025-03-18 14:10', 1, 2),
126(8, 'BA730', 2, '2025-03-18 15:10', 1, 2),
127(9, 'BA805', 2, '2025-03-18 11:40', 1, 2),
128(10, 'BA278', 2, '2025-03-18 12:55', 1, 2),
129(11, 'BA830', 2, '2025-03-18 08:25', 1, 2),
130(12, 'BA383', 2, '2025-03-18 17:15', 1, 2),
131(13, 'BA345', 2, '2025-03-18 20:00', 1, 2),
132(14, 'BA798', 1, '2025-03-18 09:00', 1, 2),
133(15, 'BA115', 1, '2025-03-18 08:55', 1, 2);
134INSERT INTO booking_class_supply (booking_class_id, flight_supply_id,
135no_seats, price_gbp) VALUES
136(1, 1, 200, 98),
137(1, 2, 200, 99),
138(1, 3, 200, 107),
139(1, 4, 200, 98),
140(1, 5, 200, 107),
141(1, 6, 200, 109),
142(1, 7, 200, 114),
143(1, 8, 180, 114),
144(1, 9, 180, 119),
145(1, 10, 180, 119),
146(1, 11, 160, 124),
147(1, 12, 160, 119),
148(1, 13, 200, 124),
149(1, 14, 200, 161),
150(1, 15, 200, 111),
151(2, 1, 20, 147),
152(2, 2, 20, 148.5),
153(2, 3, 20, 160.5),
154(2, 4, 20, 147),
155(2, 5, 20, 160.5),
156(2, 6, 20, 163.5),
157(2, 7, 20, 171),
158(2, 8, 20, 171),
159(2, 9, 20, 178.5),
160(2, 10, 20, 178.5),
161(2, 11, 20, 186),
162(2, 12, 20, 178.5),
163(2, 13, 20, 186),
164(2, 14, 20, 241.5),
165(2, 15, 20, 166.5),
166(3, 1, 16, 392),
167(3, 2, 16, 396),
168(3, 3, 16, 428),
169(3, 4, 16, 392),
170(3, 5, 16, 428),
171(3, 6, 16, 436),
172(3, 7, 16, 456),
173(3, 8, 16, 456),
174(3, 9, 16, 476),
175(3, 10, 16, 476),
176(3, 11, 16, 496),
177(3, 12, 16, 476),
178(3, 13, 16, 496),
179(3, 14, 16, 644),
180(3, 15, 16, 444),
181(4, 1, 8, 882),
182(4, 2, 8, 891),
183(4, 3, 8, 963),
184(4, 4, 8, 882),
185(4, 5, 8, 963),
186(4, 6, 8, 981),
187(4, 7, 8, 1026),
188(4, 8, 8, 1026),
189(4, 9, 8, 1071),
190(4, 10, 8, 1071),
191(4, 11, 8, 1116),
192(4, 12, 8, 1071),
193(4, 13, 8, 1116),
194(4, 14, 8, 1449),
195(4, 15, 8, 999);
Want to design a database from scratch?
Design Any Database in 60 Minutes is a 7-step framework that takes you from a real-world requirement to a working schema. You can get it here: Design Any Database.