You are on page 1of 6

How to Design a Database Model for a Movie Theater Reservation System http://www.vertabelo.com/blog/technical-articles/a-database-model-for-...

15
Shares

12

Subscribe

reservation_type
id int PK
reservation_type varchar(32)

reservation
seat_reserved
id int PK
screening_id int FK id int PK
employee employee_reserved_id int N FK seat_id int FK
reservation_type_id int N FK reservation_id int FK
id int PK reservation_contact varchar(1024) screening_id int FK
username varchar(32)
reserved bool N
password varchar(100) EDIT MODEL IN YOUR BROWSER
employee_paid_id int N FK
paid bool N

1 of 6 5/23/2018, 1:02 AM
How to Design a Database Model for a Movie Theater Reservation System http://www.vertabelo.com/blog/technical-articles/a-database-model-for-...

15
Shares

12

movie
id
title

duration_min

previous screening start time + duration_min of it > this screening start time

auditorium

seats_no

seat

seat
seats_no auditorium

screening

auditorium_id screening_start
movie_id auditorium_id
screening_start

-- Tables
-- Table screening
CREATE TABLE screening (
id int NOT NULL AUTO_INCREMENT,
movie_id int NOT NULL ,
auditorium_id int NOT NULL ,
screening_start timestamp NOT NULL ,
UNIQUE INDEX Screening_ak_1 (movie_id,auditorium_id,screening_start),
CONSTRAINT Screening_pk PRIMARY KEY (id)

2 of 6 5/23/2018, 1:02 AM
How to Design a Database Model for a Movie Theater Reservation System http://www.vertabelo.com/blog/technical-articles/a-database-model-for-...

);

seat

15
Shares

12

reservation_type

employee

reservation seat_reserved

reservation
reserved reservation_type_id
employee_reserved_id
id_employee
employee_paid_id
id_employee

seat_reserved

reservation reservation.active = True

employee_reserved_id

reservation_type_id

3 of 6 5/23/2018, 1:02 AM
How to Design a Database Model for a Movie Theater Reservation System http://www.vertabelo.com/blog/technical-articles/a-database-model-for-...

reservation_contact

15
Shares employee_paid_id

12

paid

Follow @vertabelo

Like 12 Tweet

4 of 6 5/23/2018, 1:02 AM
How to Design a Database Model for a Movie Theater Reservation System http://www.vertabelo.com/blog/technical-articles/a-database-model-for-...

11 Comments vertabelo 1 Login

Recommend 1 Share Sort by Best

Join the discussion…


15
Shares LOG IN WITH
OR SIGN UP WITH DISQUS ?

12

Frank Lucas • 7 months ago


In this instance would you generate all tickets to a screening before any reservation or
generate a ticket after a payment?
• Reply • Share ›

edrkusic Mod Frank Lucas • 7 months ago


Hi Frank. I reserve existing seats so that would be generating reservations after they
are made. We could also do that before the reservation really happened, but I
wouldn't do it so. In that case, you should generate a ticket for each seat and then
mark if it was sold. I'm not comfortable with generating information that doesn't exist
in the real world (ticket is not printed before sales).
• Reply • Share ›

vsa vsaef3f • 7 months ago


if 3 users book ticket at same time how to insert the minimun(first) one using mysql without
transaction and locking this is for fcfs basis in mysql
• Reply • Share ›

edrkusic Mod vsa vsaef3f • 7 months ago


I don't see why would you do it without transactions. When you move to the
programming part you need to use transactions in order to avoid such cases.
• Reply • Share ›

vsa vsaef3f edrkusic • 7 months ago


can you pls give me sql query logic without using transa
• Reply • Share ›

edrkusic Mod vsa vsaef3f • 7 months ago


As I said, I don't see why not to use transactions, so please use them.
• Reply • Share ›

divyenduz • a year ago


Excellent read, I think there is a typo in step 3 SQL

UNIQUE INDEX Screening_ak_1 (movie_id,auditorium_id,screening_start),

Should be

UNIQUE INDEX Screening_ak_1 (auditorium_id,screening_start),

Also, what is your opinion on using NoSQL for storing half of the data like audi and it's seats
? Albeit, it will make more sense to have the reservation mechanism as relational because of
the nature of the data.
• Reply • Share ›

edrkusic Mod divyenduz • a year ago


Thx for the note. You're right, it could be misinterpreted, because CREATE TABLE
shows first version that include movie_id. I left it only because it's simpler to remove
movie_id from the UNIQUE then add it.

I wouldn't use NoSQL if not really needed here. If a relational model works fine I
would leave it that way and think of other options in case we have performance
issues.
• Reply • Share ›

vsa vsaef3f edrkusic • 7 months ago


if 3 users book ticket at same time how to insert the minimun(first) one using
mysql without transaction and locking
• Reply • Share ›

edrkusic Mod vsa vsaef3f • 7 months ago


Answered above.
• Reply • Share ›

karthik • 7 months ago


how to check if the seat is already booked or not?
• Reply • Share ›

VERTABELO

5 of 6 5/23/2018, 1:02 AM
How to Design a Database Model for a Movie Theater Reservation System http://www.vertabelo.com/blog/technical-articles/a-database-model-for-...

15
Shares

12

6 of 6 5/23/2018, 1:02 AM

You might also like