Smart Parking System in SQL
Smart Parking System in SQL
Madhur Mahajan
CSE Semester 4
May 2025
Table of Contents
Contents
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Problem Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Functional Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Non-Functional Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2
Stakeholders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Normalization Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9
Creating Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Inserting Sample Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Sample Queries for Functionality Demonstration . . . . 11
Functional Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Performance Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Scalability Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
0
Smart Parking System: Relational Database
Management System End Sem Project
Madhur Mahajan
Roll No: 2023A1R084
Model Institute of Engineering & Technology, Jammu
CSE Semester 4
Introduction
The rapid urbanization and increasing vehicle ownership in modern cities have escalated
the demand for efficient p arking m anagement s olutions. T raditional p arking systems,
often reliant on manual processes, suffer from inefficiencies such as prolonged search times
for available slots, errors in payment processing, and suboptimal space utilization. The
Smart Parking System is a database-driven solution designed to address these challenges
by leveraging the principles of Relational Database Management Systems (RDBMS). This
project aims to create a robust backend system to manage user registrations, parking slot
allocations, bookings, and payment transactions seamlessly.
This project integrates concepts of database design with practical implementation
using MySQL. The system ensures data integrity, scalability, and real-time tracking of
parking slot avail-ability, thereby enhancing user convenience and operational e iciency.
Problem Statement
Parking facilities in urban areas face significant challenges due to limited space and in-
creasing demand. Manual parking management systems are prone to errors, such as
double-booking of slots or inaccurate payment records, and often fail to provide real-time
information on slot availability. These ine iciencies lead to user frustration, wasted time,
and reduced revenue for parking facility operators. The Smart Parking System aims to
address these issues by developing a relational database system that automates parking
management processes, ensuring accuracy, e iciency, and user satisfaction.
1
Objectives
The primary objective of this project is to design and implement a relational database
system that supports the following functionalities:
• Definition and management of multiple parking lots with unique locations and slot
capacities.
Functional Requirements
The system must fulfill the following functional requirements:
1. User Management: Allow users to register with details such as name, email,
phone number, and vehicle number, ensuring unique identification and secure data
storage.
2. Parking Lot Management: Enable the creation of multiple parking lots, each
with a unique name, location, and total slot capacity.
3. Slot Management: Track the availability status of individual parking slots within
each lot, updating the status upon booking or release.
5. Payment Processing: Record payment details for each booking, including the
amount, payment time, and status (e.g., pending, completed, or failed).
Non-Functional Requirements
In addition to functional requirements, the system must meet the following non-functional
requirements:
• Scalability: The database should handle a growing number of users, parking lots,
and transactions without performance degradation.
• Data Integrity: Ensure consistency and accuracy through primary key, foreign
key, and check constraints.
• Usability: Provide a clear and intuitive database schema that can be easily inte-
grated with a front-end application.
2
Stakeholders
The primary stakeholders of the Smart Parking System include:
• Users: Individuals who need to park their vehicles and seek a hassle-free booking
experience.
• Parking Facility Operators: Entities responsible for managing parking lots and
ensuring efficient slot utilization.
Stakeholder Requirements
Users Easy registration, real-time slot availability,
secure payment processing
Parking Facility Oper- Accurate slot tracking, automated booking
ators management, revenue tracking
System Administra- Scalable database, robust constraints, effi-
tors cient query performance
3
Conceptual Design with ER Diagram
The ER diagram provides a visual representation of the system’s entities, their attributes,
and the relationships between them. The system comprises five main entities: Users,
Parking Lots, Parking Slots, Bookings, and Payments. Below is the description of the ER
diagram, with a placeholder space for the diagram itself.
• Parking Slots: slot_id (PK), lot_id (FK → Parking Lots), slot_number, is_available
• Bookings → Parking Slots: One booking reserves exactly one slot (1:1).
• Parking Slots → Parking Lots: Multiple slots belong to one parking lot (N:1).
Diagram Representation:
• Foreign Keys are represented with linked connections to their parent entity.
4
Figure 1: Entity-Relationship Diagram for Smart Parking System
5
• Parking Lots: Stores details of each parking location.
– lot_id (INT, PRIMARY KEY, AUTO_INCREMENT): Unique identifier for
each parking lot.
– lot_name (VARCHAR(100), NOT NULL): Name of the parking lot.
– location (VARCHAR(255), NOT NULL): Location of the parking lot.
– total_slots (INT, NOT NULL, CHECK (total_slots > 0)): Total number of
slots in the lot.
– Constraints: unq_lot_location ensures the combination of lot name and loca-
tion is unique.
• Parking Slots: Stores slot-level information linked to parking lots.
– slot_id (INT, PRIMARY KEY, AUTO_INCREMENT): Unique identifier for
each slot.
– lot_id (INT, NOT NULL, FOREIGN KEY): References lot_id in Parking
Lots.
– slot_number (INT, NOT NULL): Slot number within the lot.
– is_available (BOOLEAN, DEFAULT TRUE): Indicates slot availability.
– Constraints: unq_slot_per_lot ensures slot numbers are unique within each
lot, foreign key with ON DELETE CASCADE.
• Bookings: Records each reservation with timestamps.
– booking_id (INT, PRIMARY KEY, AUTO_INCREMENT): Unique identifier
for each booking.
– user_id (INT, NOT NULL, FOREIGN KEY): References user_id in Users.
– slot_id (INT, NOT NULL, FOREIGN KEY): References slot_id in Parking
Slots.
– booking_time (DATETIME, NOT NULL, DEFAULT CURRENT_TIMESTAMP):
Time of booking.
– release_time (DATETIME, NULL): Time of slot release.
– Constraints: chk_valid_booking_time ensures release time is either null or
greater than or equal to booking time, foreign keys with ON DELETE CAS-
CADE.
• Payments: Stores transaction data linked to bookings.
– payment_id (INT, PRIMARY KEY, AUTO_INCREMENT): Unique identi-
fier for each payment.
– booking_id (INT, NOT NULL, FOREIGN KEY): References booking_id in
Bookings.
– amount (DECIMAL(10,2), NOT NULL, CHECK (amount > 0)): Payment
amount.
– payment_time (DATETIME, NOT NULL, DEFAULT CURRENT_TIMESTAMP):
Time of payment.
6
– payment_status (ENUM(’pending’, ’completed’, ’failed’), DEFAULT ’pend-
ing’): Status of the payment.
– Constraints: Foreign key with ON DELETE CASCADE.
This schema ensures data integrity through primary keys, foreign keys with cascading
deletions, and business rules enforced by CHECK constraints.
Normalization Analysis
The relational schema is evaluated to ensure it meets at least the 3rd Normal Form (3NF):
• Users Table:
• Bookings Table:
7
• Payments Table:
– 1NF: All attributes are atomic.
– 2NF: Single candidate key (payment_id), no partial dependencies.
– 3NF: All attributes depend on payment_id. The foreign key booking_id is
appropriate.
– Conclusion: The Payments table is in 3NF.
8
Implementation
The implementation begins with creating the database tables, followed by populating
them with sample data to simulate real-world usage.
Creating Tables
The following SQL statements create the tables for the Smart Parking System, as defined
in the schema:
9
33 booking_id INT AUTO_INCREMENT PRIMARY KEY ,
34 user_id INT NOT NULL ,
35 slot_id INT NOT NULL ,
36 booking_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ,
37 release_time DATETIME NULL ,
38 FOREIGN KEY ( user_id ) REFERENCES Users( user_id ) ON DELETE
CASCADE ,
39 FOREIGN KEY ( slot_id ) REFERENCES Parking_Slots ( slot_id ) ON
DELETE CASCADE ,
40 CONSTRAINT chk_valid_booking_time CHECK (
41 release_time IS NULL OR release_time >= booking_time
42 )
43 );
44
17 -- Insert Users
18 INSERT INTO Users (name , email , phone , vehicle_number )
19 VALUES
10
20 ('John Doe ', 'john@example .com ', '9876543210 ', 'DL01AB1234 '),
21 ('Alice Smith ', 'alice@example .com ', '9876543211 ',
'MH12XY4567 '),
22 ('Rahul Verma ', 'rahul@example .com ', '9123456789 ',
'KA01CD7890 ');
23
11
Query 2: View a User’s Booking History
This query shows all bookings made by a specific user (e.g., user_id = 1), including
parking slot and lot details.
1 SELECT b. booking_id , b. booking_time , b. release_time ,
2 ps. slot_number , pl.lot_name , pl. location
3 FROM Bookings b
4 JOIN Parking_Slots ps ON b. slot_id = ps. slot_id
5 JOIN Parking_Lots pl ON ps. lot_id = pl. lot_id
6 WHERE b. user_id = 1
7 ORDER BY b. booking_time DESC;
12
Query 4: Release a Parking Slot and Update Availability
This query simulates a user releasing a parking slot (e.g., slot_id = 1) by updating the
booking’s release time and setting the slot as available again.
1 UPDATE Bookings
2 SET release_time = NOW ()
3 WHERE slot_id = 1 AND release_time IS NULL;
4
5 UPDATE Parking_Slots
6 SET is_available = TRUE
7 WHERE slot_id = 1;
Figure : Output of Query 4: Updated Booking and Slot Availability for Slot 1
13
Figure : Output of Query 5: Total Revenue from Completed Payments
14
1 SELECT b. booking_id , b. booking_time , u.name , u.email ,
2 ps. slot_number , pl. lot_name
3 FROM Bookings b
4 JOIN Users u ON b. user_id = u. user_id
5 JOIN Parking_Slots ps ON b. slot_id = ps. slot_id
6 JOIN Parking_Lots pl ON ps. lot_id = pl. lot_id
7 WHERE b. release_time IS NULL
8 AND b. booking_time < DATE_SUB (NOW (), INTERVAL 24 HOUR);
15
Database Implementation Overview
The Smart Parking System database was implemented in the previous section by creating
the necessary tables and inserting sample data. The tables include:
• Primary Keys and AUTO_INCREMENT ensure unique identifiers for each record.
• CHECK constraints enforce business rules, such as valid email formats, phone num-
ber lengths, and positive payment amounts.
The sample data inserted includes users, parking lots, parking slots, bookings, and
payments, simulating real-world usage scenarios. This setup allows us to test the database’s
functionality and performance under various conditions.
16
Identifying Columns for Indexing
Based on the sample queries from the previous section, the following columns are fre-
quently used in WHERE clauses, JOIN conditions, and ORDER BY clauses, making
them candidates for indexing:
Foreign key columns (e.g., lot_id, user_id, slot_id, booking_id) are particularly
important to index, as they are often used in JOIN operations. Additionally, columns used
in filtering (e.g., is_available) and sorting (e.g., booking_time) benefit from indexing.
Creating Indexes
The following SQL statements create indexes on the identified columns:
1 -- Index on Parking_Slots . lot_id for faster JOINs and filtering
2 CREATE INDEX idx_parking_slots_lot_id ON Parking_Slots ( lot_id );
3
These indexes are named with the prefix idx_ to indicate they are indexes, followed
by the table and column names for clarity.
17
Impact of Indexing
To demonstrate the impact of indexing, we can compare the performance of a query
before and after adding the indexes. Consider the query to find available parking slots
in a specific lot (lot_id = 1):
1 SELECT ps.slot_id , ps. slot_number , pl.lot_name , pl. location
2 FROM Parking_Slots ps
3 JOIN Parking_Lots pl ON ps. lot_id = pl. lot_id
4 WHERE ps. is_available = TRUE AND ps. lot_id = 1;
Before Indexing: Without indexes on lot_id and is_available, the database per-
forms a full table scan on Parking_Slots, which can be slow for large datasets.
After Indexing: With idx_parking_slots_lot_id and idx_parking_slots_is_available,
the database can quickly locate the relevant rows using the indexes, significantly reducing
query execution time.
Below is a placeholder space for embedding the query execution plan or performance
metrics (e.g., from MySQL’s EXPLAIN statement) before indexing:
Figure a: Query Execution Plan Before Indexing (Find Available Slots in Lot 1)
Figure b: Query Execution Plan After Indexing (Find Available Slots in Lot 1)
18
The execution plans ( in Figures a and b) should show a reduction in the number of
rows scanned and the use of the indexes after they are created.
Trade-Offs o f Indexing
While indexes improve read performance, they have some drawbacks:
• Increased Storage: Indexes require additional disk space, proportional to the size
of the indexed columns and the number of rows.
• Slower Write Operations: INSERT, UPDATE, and DELETE operations are
slower because the indexes must be updated whenever the indexed columns are
modified.
• Maintenance Overhead: Indexes need to be maintained during database operations,
which can add overhead, especially for tables with frequent updates.
For the Smart Parking System, the trade-offs are acceptable because:
• Read operations (e.g., finding available slots, viewing booking history) are more
frequent than write operations.
• The dataset size is manageable, so the additional storage and maintenance overhead
of indexes are minimal.
The output should show the same results as before but with improved performance
due to the indexes.
19
Query 2: View User Booking History with Index
This query uses the index on user_id to retrieve the booking history for user_id = 1.
The output benefits from the indexes on user_id, slot_id, and booking_time,
resulting in faster filtering and sorting.
20
*
Functional Testing
Functional testing verifies that the database implementation meets the specified require-
ments. The following tests were conducted:
– Test the insertion of data into all tables (Users, Parking_Lots, Parking_Slots,
Bookings, Payments).
– Verify that constraints are enforced:
∗ UNIQUE constraint on Users.email prevents duplicate email addresses.
∗ CHECK constraint on Payments.amount ensures amounts are positive.
∗ FOREIGN KEY constraints with ON DELETE CASCADE correctly
delete dependent records.
• Query Accuracy:
– Test the sample queries from the previous section (e.g., finding available slots,
viewing booking history, checking payment status).
– Ensure the query results match expected outputs based on the inserted sample
data.
• Booking Workflow:
21
Figure : Error Output: Attempting to Insert Duplicate Email in Users Table
Performance Testing
Performance testing evaluates the database’s efficiency, focusing on query execution times
and scalability. The tests were conducted with the sample data and indexes applied in
the previous section.
The query execution time was measured using MySQL’s profiling t ools ( e.g., EX-
PLAIN or benchmarking). Below is a placeholder space for embedding the performance
metrics:
The metrics should show the execution time, which is expected to be low due to
the indexes on lot_id and is_available.
22
Scalability Testing
To test scalability, the dataset was expanded by inserting more records into the Users, Bookings, and
Payments tables:
The query to view a user’s booking history was then executed with the expanded
dataset:
1 SELECT b. booking_id , b. booking_time , b. release_time ,
2 ps. slot_number , pl.lot_name , pl. location
3 FROM Bookings b
4 JOIN Parking_Slots ps ON b. slot_id = ps. slot_id
5 JOIN Parking_Lots pl ON ps. lot_id = pl. lot_id
6 WHERE b. user_id = 1
7 ORDER BY b. booking_time DESC;
The results should show that the query remains efficient due to the indexes, even
with a larger dataset. However, further optimization (e.g., partitioning large tables)
may be needed for production-scale data.
Figure 3: Scalability Test: Performance of Booking History Query with Expanded Dataset
23
Results and Optimizations
The functional tests confirmed that the database operates as expected, with all con-
straints enforced and queries returning accurate results. Performance tests showed that
the indexes significantly reduced query execution times, especially for read-heavy oper-
ations. Scalability tests indicated that the system handles moderate data growth well,
but future improvements could include:
• Partitioning: For very large datasets, partitioning the Bookings table by date
range could improve performance.
• Caching: Implementing a caching layer for frequently accessed data (e.g., available
slots) could reduce database load.
24
References
The following resources were consulted during the development and documentation of
the Smart Parking System:
Books
• Silberschatz, A., Korth, H. F., & Sudarshan, S. (2010). Database System Concepts
(6th ed.). McGraw-Hill Education.
This textbook provides a foundational understanding of database management
concepts, including schema design, normalization, and query optimization, which
guided the development of the Smart Parking System.
• Elmasri, R., & Navathe, S. B. (2015). Fundamentals of Database Systems (7th ed.).
Pearson.
This book offers a comprehensive introduction to database design and implemen-
tation, emphasizing practical aspects that were applied in this project.
Websites
25