A simple PostgreSQL database project for managing football matches, users, and ticket bookings. This project demonstrates database design concepts such as table relationships, constraints, data seeding, and SQL queries.
ER Diagram Link: https://drawsql.app/teams/ayansujon/diagrams/ayan-sujon
The system manages:
- Users (Football Fans and Ticket Managers)
- Football Matches
- Ticket Bookings
The project also includes several SQL queries demonstrating:
- Filtering data
- Searching records
- Handling
NULLvalues JOINoperations- Subqueries
- Pagination using
LIMITandOFFSET
Stores information about users of the system.
| Column | Data Type | Constraints |
|---|---|---|
| user_id | SERIAL | Primary Key |
| full_name | VARCHAR(100) | NOT NULL |
| VARCHAR(100) | UNIQUE, NOT NULL | |
| role | VARCHAR(20) | CHECK ('Ticket Manager', 'Football Fan') |
| phone_number | VARCHAR(20) | Nullable |
Stores football match information.
| Column | Data Type | Constraints |
|---|---|---|
| match_id | SERIAL | Primary Key |
| fixture | VARCHAR(150) | NOT NULL |
| tournament_category | VARCHAR(100) | NOT NULL |
| base_ticket_price | DECIMAL(10,2) | CHECK >= 0 |
| match_status | VARCHAR(20) | CHECK values |
- Available
- Selling Fast
- Sold Out
- Postponed
Stores ticket booking information.
| Column | Data Type | Constraints |
|---|---|---|
| booking_id | SERIAL | Primary Key |
| user_id | INT | Foreign Key |
| match_id | INT | Foreign Key |
| seat_number | VARCHAR(20) | Nullable |
| payment_status | VARCHAR(20) | Nullable |
| total_cost | DECIMAL(10,2) | CHECK >= 0 |
- Pending
- Confirmed
- Cancelled
- Refunded
- One user can have multiple bookings.
- One booking belongs to one user.
Relationship:
Users (1) --------< Bookings (M)
- One match can have multiple bookings.
- One booking belongs to one match.
Relationship:
Matches (1) --------< Bookings (M)
Users and Matches have a Many-to-Many relationship through the Bookings table.
Users (M) --------< Bookings >-------- (M) Matches
USERS
+---------------+
| PK user_id |
| full_name |
| email |
| role |
| phone_number |
+---------------+
|
| 1
|
| M
+----------------+
| BOOKINGS |
+----------------+
| PK booking_id |
| FK user_id |
| FK match_id |
| seat_number |
| payment_status |
| total_cost |
+----------------+
|
| M
|
| 1
|
+---------------+
| MATCHES |
+---------------+
| PK match_id |
| fixture |
| tournament... |
| base_ticket...|
| match_status |
+---------------+
The database contains:
- 4 Users
- 5 Matches
- 5 Bookings
Retrieve all available Champions League matches.
Search users whose:
- Name starts with
Tanvir - Name contains
Haque
Retrieve bookings with missing payment status and replace NULL using COALESCE.
Retrieve booking details along with user name and match fixture using INNER JOIN.
Display all users and their bookings using LEFT JOIN.
Find bookings whose total cost is greater than the average booking cost using a subquery.
Retrieve the top two expensive matches while skipping the highest-priced match using OFFSET and LIMIT.
- PostgreSQL
- Beekeeper Studio
Level2-B7A3/
│
├── requerements
├── QUERY.sql
├── solution.sql
└── README.md
This project demonstrates:
- Database Design
- Primary Keys
- Foreign Keys
- One-to-Many Relationships
- Many-to-Many Relationships
- Constraints
- Joins
- Subqueries
- Aggregate Functions
- NULL Handling
- Pagination Queries
Developed as a practice project for learning PostgreSQL database design and SQL querying.