Bonus: Database Design for an AirBNB Website
What's in this guide
This guide goes with my YouTube video on designing a database for the AirBNB website. In it, you'll find:
- The Entity Relationship Diagram for an AirBNB website 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 22 tables and their columns.
property
A record for a property that can be booked on the website.
| Column | Description | Sample Data |
|---|---|---|
| id | Primary key. A unique identifier for the row. | 1, 2, 3 |
| location_id | A foreign key to the location table to indicate the location for the property | 2, 5, 7 |
| place_type_id | A foreign key to the place_type table to indicate the type of place this is. | 1, 2, 4 |
| property_type_id | A foreign key to the property_type table to indicate the type of property | 3, 4, 5 |
| host_id | A foreign key to the user_account table to indicate who the host of this property is. | 1, 3, 8 |
| nightly_price | The price to stay one night in this property. It's assumed that all nights cost the same amount (no variation for weekends) and the price is in a single currency (such as US Dollars) | 200, 450, 120 |
| property_name | The name of the property, shown in emails and on the top of the property page | Wensley - Rustic Luxury, Great Ocean Rd Hinterland |
| num_guests | The maximum number of guests that can stay in the property | 2, 4, 10 |
| num_beds | The number of beds available in the property | 1, 2, 4 |
| num_bedrooms | The number of bedrooms in the property | 1, 2, 6 |
| num_bathrooms | The number of bathrooms in the property | 1, 2 |
| is_guest_favourite | Whether or not this property is a "guest favourite" | 0 (No) or 1 (Yes) |
| description | A long description of the property, to be shown on the property page. | "Set high on the rolling hills of 80 acres The Wensley is a…" |
| address_line_1 | The first line of the address of this property | Unit 10 |
| address_line_2 | The second line of the address of this property | 123 Smith St |
category
A lookup table for the different categories that can be applied to a property.
| Column | Description | Sample Data |
|---|---|---|
| id | Primary key. A unique identifier for the row. | 1, 2, 3 |
| category_name | The name of the category of this property. Shown across the top of the home page. | Cabin, Off-the-grid, OMG, Tiny Home |
property_category
A joining table for properties and categories.
| Column | Description | Sample Data |
|---|---|---|
| property_id | A foreign key to the property table to indicate which property this record relates to. | 1, 2, 3 |
| category_id | A foreign key to the category table to indicate which category this record relates to. | 4, 2, 10 |
attribute_category
A lookup table for the different categories that attributes can belong to.
| Column | Description | Sample Data |
|---|---|---|
| id | Primary key. A unique identifier for the row. | 1, 2, 3 |
| category_name | The name of the category to group attributes. Shown on the bottom of the property page, and can be used to show different attributes in different sections on the page. | House Rules, Safety & Property, Cancellation Policy Offerings |
attribute
A list of all the attributes that are able to be applied to a property.
| Column | Description | Sample Data |
|---|---|---|
| id | Primary key. A unique identifier for the row. | 1, 2, 3 |
| category_id | A foreign key to the attribute_category table. | 2, 4, 8 |
| attribute_name | The name of the attribute that can be applied to a property | Featured In, Designed By, Free Cancellation, Valley View, Kitchen, Wi-Fi |
| description | An optional description of the attribute | This property offers free cancellation up to 2 days before the booking date. |
property_attribute
A joining table of the attributes that are applied to a property.
| Column | Description | Sample Data |
|---|---|---|
| property_id | A foreign key to the property table. | 1, 2, 3 |
| attribute_id | A foreign key to the attribute table. | 3, 6, 8 |
location
A lookup table for the location of a property, which may be a city or suburb.
| Column | Description | Sample Data |
|---|---|---|
| id | Primary key. A unique identifier for the row. | 1, 2, 3 |
| country_id | A foreign key to the country table to indicate which country this location is in | 1, 4, 7 |
| location_name | The name of the location, which is shown in several places on the website. | Point Lonsdale, Swansea, Loceri |
country
A lookup table for the country that the property is in.
| Column | Description | Sample Data |
|---|---|---|
| id | Primary key. A unique identifier for the row. | 1, 2, 3 |
| region_id | A foreign key to the region table. | 3, 4, 8 |
| country_name | The name of the country. | Australia, Italy, United States |
region
A lookup table for the region in the world that the country is in.
| Column | Description | Sample Data |
|---|---|---|
| id | Primary key. A unique identifier for the row. | 1, 2, 3 |
| region_name | The name of the region to be shown on the website | Europe, Southeast Asia, Oceania |
place_type
A lookup able for the "type of place", which is either a Room or an Entire Home.
| Column | Description | Sample Data |
|---|---|---|
| id | Primary key. A unique identifier for the row. | 1, 2, 3 |
| type_name | The name of this type of place. | Room, Entire Home |
property_type
A lookup table for the type of property, such as House or Apartment.
| Column | Description | Sample Data |
|---|---|---|
| id | Primary key. A unique identifier for the row. | 1, 2, 3 |
| type_name | The name of this type of property | House, Apartment, Guest House, Hotel |
user_account
A table for the users who access the website, make bookings, leave reviews, and host properties.
| Column | Description | Sample Data |
|---|---|---|
| id | Primary key. A unique identifier for the row. | 1, 2, 3 |
| first_name | The first name of the user, and can be used to show as the "host name" on properties. | Judy |
| last_name | The last name of the user | Smith |
| email_address | The email address for the user, which can be used to send booking details to and to log in. | john@apple.com |
| password | The password for the user's account on the website | An encrypted text value |
| joined_date | The date that the user has joined the site | 2023-03-02 |
| date_host_started | The date that the user became a host |
favourite
A record of the properties that a user has indicated as being their favourite.
| Column | Description | Sample Data |
|---|---|---|
| property_id | A foreign key to the property table that is made a favourite. | 1, 2, 3 |
| user_id | A foreign key to the user_account table for the user who made the favourite. | 2, 3, 17 |
user_review
A record for a review left by a user on a property.
| Column | Description | Sample Data |
|---|---|---|
| id | Primary key. A unique identifier for the row. | 1, 2, 3 |
| property_id | A foreign key to the property table that was reviewed. | 1, 3, 6 |
| user_id | A foreign key to the user_account that made the review. | 1, 6, 7 |
| overall_rating | The rating provided for the property overall for this user. | 1, 2, 3, 4, 5 |
| comment | A text comment left by the user as part of the review | "A great little property that we really enjoyed staying at…" |
| review_date | The date the review was made. | 2023-01-04 |
component_rating
A joining table of the review components for a property, and the rating for each of them for the property.
| Column | Description | Sample Data |
|---|---|---|
| component_id | A foreign key to the review_component table | 1, 2, 3 |
| review_id | A foreign key to the user_review table | 1, 4, 5 |
| rating | A number rating made for this component for this review by the user. | 1, 2, 3, 4, 5 |
review_component
A lookup table for all of the areas that can be reviewed for a property.
| Column | Description | Sample Data |
|---|---|---|
| id | Primary key. A unique identifier for the row. | 1, 2, 3 |
| component_name | The name of the component of the review, which is displayed to the users. | Cleanliness, Accuracy, Check-in, Communication, Location, Value |
booking
A record for a booking for a property.
| Column | Description | Sample Data |
|---|---|---|
| id | Primary key. A unique identifier for the row. | 1, 2, 3 |
| property_id | A foreign key to the property table for the property that is booked. | 2, 4, 10 |
| user_id | A foreign key to the user_account table for the user who made the booking. | 2, 4, 9 |
| booking_status_id | A foreign key to the booking_status table to capture the status of this booking. | 1, 2, 3 |
| checkin_date | The check-in date for this booking. | 2023-05-07 |
| checkout_date | The check-out date for this booking. | 2023-05-11 |
| nightly_price | The price of a single night for this booking. It's in this table so that it is kept for a booking even if the property.nightly_price changes. | 120 |
| service_fee | The service fee for the booking. | 15 |
| cleaning_fee | The cleaning fee for the booking. | 20 |
| total_price | The total price to pay for this booking. | 155 |
booking_guests
A joining table for the number of guests of each type for a booking.
| Column | Description | Sample Data |
|---|---|---|
| booking_id | A foreign key to the booking table, to store the booking for this record. | 1, 2, 3 |
| guest_type_id | A foreign key to the guest_type table for the relevant guest_type. | 1, 2, 3 |
| num_guests | The number of guests of this type for this booking | 2, 5, 8 |
guest_type
A lookup table for the type of guests on a booking, such as Adults and Children.
| Column | Description | Sample Data |
|---|---|---|
| id | Primary key. A unique identifier for the row. | 1, 2, 3 |
| type_name | The name of this guest type, which is shown to the user when making a booking. | Adults, Children, Infants, Pets |
booking_status
A lookup table for the status of a booking.
| Column | Description | Sample Data |
|---|---|---|
| id | Primary key. A unique identifier for the row. | 1, 2, 3 |
| status_name | A value that describes the status of the booking | Awaiting Approval, Approved, Cancelled, Completed |
language
A lookup table for the language spoken by a user, to assist with communication and check-in.
| Column | Description | Sample Data |
|---|---|---|
| id | Primary key. A unique identifier for the row. | 1, 2, 3 |
| language_name | The name of the spoken language | English, Mandarin, Italian |
user_language
A joining table for the languages spoken by a user.
| Column | Description | Sample Data |
|---|---|---|
| user_id | A foreign key to the user_account table. | 1, 2, 3 |
| language_id | A foreign key to the language table | 1, 4, 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 airbnb;
2
3USE airbnb;
4CREATE DATABASE airbnb;
5
6USE airbnb;
7DROP TABLE IF EXISTS booking_guests;
8DROP TABLE IF EXISTS guest_type;
9DROP TABLE IF EXISTS booking;
10DROP TABLE IF EXISTS booking_status;
11DROP TABLE IF EXISTS component_rating;
12DROP TABLE IF EXISTS user_review;
13DROP TABLE IF EXISTS review_component;
14DROP TABLE IF EXISTS property_attribute;
15DROP TABLE IF EXISTS property_category;
16DROP TABLE IF EXISTS favourite;
17DROP TABLE IF EXISTS property;
18DROP TABLE IF EXISTS user_account;
19DROP TABLE IF EXISTS property_type;
20DROP TABLE IF EXISTS place_type;
21DROP TABLE IF EXISTS location;
22DROP TABLE IF EXISTS country;
23DROP TABLE IF EXISTS region;
24DROP TABLE IF EXISTS attribute;
25DROP TABLE IF EXISTS attribute_category;
26DROP TABLE IF EXISTS category;
27
28CREATE TABLE category (
29 id INT,
30 category_name VARCHAR(200),
31 CONSTRAINT pk_category PRIMARY KEY (id)
32);
33
34CREATE TABLE attribute_category (
35 id INT,
36 category_name VARCHAR(200),
37 CONSTRAINT pk_attrcat PRIMARY KEY (id)
38);
39
40CREATE TABLE attribute (
41 id INT,
42 category_id INT,
43 attribute_name VARCHAR(200),
44 description VARCHAR(500),
45 CONSTRAINT pk_attribute PRIMARY KEY (id),
46 CONSTRAINT fk_att_category FOREIGN KEY (category_id) REFERENCES attribute_category (id)
47);
48
49CREATE TABLE region (
50 id INT,
51 region_name VARCHAR(200),
52 CONSTRAINT pk_region PRIMARY KEY (id)
53);
54
55CREATE TABLE country (
56 id INT,
57 region_id INT,
58 country_name VARCHAR(200),
59 CONSTRAINT pk_country PRIMARY KEY (id),
60 CONSTRAINT fk_country_reg FOREIGN KEY (region_id) REFERENCES region (id)
61);
62
63CREATE TABLE location (
64 id INT,
65 country_id INT,
66 location_name VARCHAR(200),
67 CONSTRAINT pk_location PRIMARY KEY (id),
68 CONSTRAINT fk_location_country FOREIGN KEY (country_id) REFERENCES country (id)
69);
70
71CREATE TABLE place_type (
72 id INT,
73 type_name VARCHAR(200),
74 CONSTRAINT pk_placetype PRIMARY KEY (id)
75);
76
77CREATE TABLE property_type (
78 id INT,
79 type_name VARCHAR(200),
80 CONSTRAINT pk_propertytype PRIMARY KEY (id)
81);
82
83CREATE TABLE user_account (
84 id INT,
85 first_name VARCHAR(300),
86 last_name VARCHAR(300),
87 email_address VARCHAR(350),
88 password VARCHAR(200),
89 joined_date DATE,
90 date_host_started DATE,
91 CONSTRAINT pk_user PRIMARY KEY (id)
92);
93
94CREATE TABLE property (
95 id INT,
96 location_id INT,
97 place_type_id INT,
98 property_type_id INT,
99 host_id INT,
100 nightly_price INT,
101 property_name VARCHAR(200),
102 num_guests INT,
103 num_beds INT,
104 num_bedrooms INT,
105 num_bathrooms INT,
106 is_guest_favourite INT,
107 description VARCHAR(2000),
108 address_line_1 VARCHAR(500),
109 address_line_2 VARCHAR(500),
110 CONSTRAINT pk_property PRIMARY KEY (id),
111 CONSTRAINT fk_property_loc FOREIGN KEY (location_id) REFERENCES location (id),
112 CONSTRAINT fk_property_placetype FOREIGN KEY (place_type_id) REFERENCES place_type (id),
113 CONSTRAINT fk_property_proptype FOREIGN KEY (property_type_id) REFERENCES property_type (id),
114 CONSTRAINT fk_property_host FOREIGN KEY (host_id) REFERENCES user_account (id)
115);
116
117CREATE TABLE favourite (
118 property_id INT,
119 user_id INT,
120 CONSTRAINT fk_fav_prop FOREIGN KEY (property_id) REFERENCES property (id),
121 CONSTRAINT fk_fav_user FOREIGN KEY (user_id) REFERENCES user_account (id)
122);
123
124CREATE TABLE property_category (
125 property_id INT,
126 category_id INT,
127 CONSTRAINT fk_propertycat_prop FOREIGN KEY (property_id) REFERENCES property (id),
128 CONSTRAINT fk_propertycat_cat FOREIGN KEY (category_id) REFERENCES category (id)
129);
130
131CREATE TABLE property_attribute (
132 property_id INT,
133 attribute_id INT,
134 CONSTRAINT fk_propcat_prop FOREIGN KEY (property_id) REFERENCES property (id),
135 CONSTRAINT fk_propcat_cat FOREIGN KEY (attribute_id) REFERENCES attribute (id)
136);
137
138CREATE TABLE review_component (
139 id INT,
140 component_name VARCHAR(100),
141 CONSTRAINT pk_reviewcomp PRIMARY KEY (id)
142);
143
144CREATE TABLE user_review (
145 id INT,
146 property_id INT,
147 user_id INT,
148 overall_rating INT,
149 comment VARCHAR(2000),
150 review_date DATE,
151 CONSTRAINT pk_userreview PRIMARY KEY (id),
152 CONSTRAINT fk_userreview_prop FOREIGN KEY (property_id) REFERENCES property (id),
153 CONSTRAINT fk_userreview_user FOREIGN KEY (user_id) REFERENCES user_account (id)
154);
155
156CREATE TABLE component_rating (
157 component_id INT,
158 review_id INT,
159 rating INT,
160 CONSTRAINT fk_comprat_comp FOREIGN KEY (component_id) REFERENCES review_component (id),
161 CONSTRAINT fk_comprat_review FOREIGN KEY (review_id) REFERENCES user_review (id)
162);
163
164CREATE TABLE booking_status (
165 id INT,
166 status_name VARCHAR(50),
167 CONSTRAINT pk_bookingstatus PRIMARY KEY (id)
168);
169
170CREATE TABLE booking (
171 id INT,
172 property_id INT,
173 user_id INT,
174 booking_status_id INT,
175 checkin_date DATE,
176 checkout_date DATE,
177 nightly_price INT,
178 service_fee INT,
179 cleaning_fee INT,
180 total_price INT,
181 CONSTRAINT pk_booking PRIMARY KEY (id),
182 CONSTRAINT fk_booking_prop FOREIGN KEY (property_id) REFERENCES booking (id),
183 CONSTRAINT fk_booking_user FOREIGN KEY (user_id) REFERENCES user_account (id),
184 CONSTRAINT fk_booking_bookstatus FOREIGN KEY (booking_status_id) REFERENCES booking_status (id)
185);
186
187CREATE TABLE guest_type (
188 id INT,
189 type_name VARCHAR(50),
190 CONSTRAINT pk_guesttype PRIMARY KEY (id)
191);
192
193CREATE TABLE booking_guests (
194 booking_id INT,
195 guest_type_id INT,
196 num_guests INT,
197 CONSTRAINT fk_bkguest_booking FOREIGN KEY (booking_id) REFERENCES booking (id),
198 CONSTRAINT fk_bkguest_guesttype FOREIGN KEY (guest_type_id) REFERENCES guest_type (id)
199);
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.