guests
People who make reservations.
Reservation systems separate what a room is (its type and price) from which physical room a guest gets. This schema keeps that split, which makes pricing and availability much easier to manage.
People who make reservations.
Properties in the system, each in one city.
Kinds of room a hotel offers, such as “Double” or “Suite”, with a nightly rate and capacity.
Individual physical rooms. Each is of one type.
A guest staying in a specific room between two dates.
room_types.hotel_id references hotels.id: one row in hotels can have many rows in room_types.rooms.room_type_id references room_types.id: one row in room_types can have many rows in rooms.bookings.guest_id references guests.id: one row in guests can have many rows in bookings.bookings.room_id references rooms.id: one row in rooms can have many rows in bookings.Copy it into your database, or open it in Crowsfoot to edit the diagram, add notes, and export again.
CREATE TABLE guests (
id bigint PRIMARY KEY,
name varchar(120) NOT NULL,
email varchar(255) NOT NULL
);
CREATE TABLE hotels (
id bigint PRIMARY KEY,
name varchar(160) NOT NULL,
city varchar(80) NOT NULL
);
CREATE TABLE room_types (
id bigint PRIMARY KEY,
hotel_id bigint NOT NULL REFERENCES hotels (id),
name varchar(80) NOT NULL,
nightly_rate numeric(10,2) NOT NULL,
capacity int NOT NULL
);
CREATE TABLE rooms (
id bigint PRIMARY KEY,
room_type_id bigint NOT NULL REFERENCES room_types (id),
number varchar(10) NOT NULL,
floor int
);
CREATE TABLE bookings (
id bigint PRIMARY KEY,
guest_id bigint NOT NULL REFERENCES guests (id),
room_id bigint NOT NULL REFERENCES rooms (id),
check_in date NOT NULL,
check_out date NOT NULL,
status varchar(20) NOT NULL DEFAULT 'confirmed'
);
New to ER diagrams? Read the crow’s foot notation guide.