dbms
dbms
Objective: Develop a database schema and implement SQL queries for a real-time
inventory management system.
Exercise:
o Scenario: You are tasked with building an inventory management system for
a warehouse. The system needs to track product quantities, product categories,
suppliers, and orders.
o Tasks:
1. Design a normalized schema with tables for products, inventory
transactions (e.g., purchases, sales), suppliers, and product categories.
2. Create a stored procedure to update inventory levels in real time when
products are purchased or sold.
3. Implement complex SQL queries to generate real-time reports, such as
“current stock of a product,” “low stock products,” and “supplier order
history.”
4. Implement an auto-update feature using triggers to decrease inventory
when a product is sold or shipped.
5. Discuss how you would handle concurrent inventory updates to avoid
issues like double selling.
Objective: Build a schema for a social media platform and apply concepts such as
joins, indexing, and user activity tracking.
Exercise:
o Scenario: Design a database for a social media platform like Facebook or
Instagram, where users can post content, like, comment, and follow others.
o Tasks:
1. Design normalized tables for users, posts, comments, likes, followers,
and notifications.
2. Create SQL queries to retrieve feeds for a specific user (combine posts,
likes, and comments).
3. Implement a system for tracking user activities such as following users
or liking posts. Write a query to find the “most liked posts” or “most
followed users.”
4. Use indexing on frequently queried fields (e.g., user_id, post_id) to
optimize performance.
5. Advanced: Write a stored procedure that automatically sends
notifications to users when their posts are liked or commented on.
Objective: Design a star schema for OLAP (Online Analytical Processing) and
implement data cubes.
Exercise:
o Scenario: You are tasked with designing a data warehouse for a retail business
to analyze sales performance across various dimensions such as time, product,
and geography.
o Tasks:
1. Design the schema using the star schema model with fact tables and
dimension tables (e.g., sales fact, product dimension, time dimension,
store dimension).
2. Write SQL queries to perform OLAP operations like slice, dice, roll-
up, and drill-down to analyze sales by different dimensions.
3. Design a query to calculate the total sales by region, month, and
product category.
4. Implement an ETL process to populate the fact and dimension tables
from transactional data.
5. Advanced: Create materialized views for frequently queried reports to
speed up query performance.
Objective: Build a database for managing movie showtimes, bookings, and user
profiles.
Exercise:
o Scenario: Build a database for a movie ticket reservation system where users
can view showtimes, book tickets, and review movies.
o Tasks:
1. Design tables for users, movies, theaters, showtimes, bookings, and
reviews.
2. Create relationships between users and bookings, and between
showtimes and movies.
3. Implement a query to get the "most booked movie" over the past
month.
4. Implement a stored procedure to automatically send reminders for
booked tickets 24 hours before the showtime.
5. Advanced: Handle concurrent seat bookings by implementing locks to
prevent double bookings during peak hours.
Objective: Build a system for tracking live sports scores, teams, players, and
statistics.
Exercise:
o Scenario: You are designing a real-time sports scoring system to track the
scores, players, and statistics during live games (e.g., for soccer, basketball,
etc.).
o Tasks:
1. Design tables for teams, players, matches, scores, and statistics.
2. Implement real-time updates to the database using triggers or stored
procedures for scoring events.
3. Write queries to generate match summaries such as “Total points
scored by a player,” “Team with the most wins,” and “Player statistics
by game.”
4. Advanced: Implement concurrency control mechanisms to handle
simultaneous updates to player statistics during high-paced games.
Objective: Design and implement a database for booking flights, hotels, and car
rentals.
Exercise:
o Scenario: Create a database to handle the booking process for flights, hotels,
and car rentals for a travel agency.
o Tasks:
1. Design tables for customers, flights, hotels, car rentals, reservations,
and payment transactions.
2. Implement foreign key relationships between customers and
reservations, reservations and bookings (e.g., flight, hotel, car).
3. Write SQL queries to generate a "Customer Booking History" report
and a "Revenue per Travel Package."
4. Advanced: Create a stored procedure to check availability for flights,
hotels, and cars based on customer preferences and issue a reservation.
5. Concurrency: Implement mechanisms to handle concurrent bookings
for limited resources (e.g., limited hotel rooms or flights).
Objective: Build a system for managing courses, students, instructors, and grades in
an online learning platform.
Exercise:
o Scenario: Design a database for an online learning system, where students can
enroll in courses, track progress, and interact with instructors.
o Tasks:
1. Design tables for students, courses, instructors, enrollments, and
assignments.
2. Create relationships for student enrollment in courses and assignment
submissions.
3. Write queries to generate reports such as "Students enrolled in a
particular course" or "Students who scored above a certain grade."
4. Advanced: Develop a stored procedure to calculate final grades based
on assignment scores, participation, and exams.
5. Normalization: Normalize the schema to remove redundancy and
ensure data integrity.
Objective: Build a library system that includes features like book reservations,
overdue tracking, and fine calculation.
Exercise:
o Scenario: Create a database for a library that allows users to borrow, reserve,
and return books. The system should also track overdue books and calculate
fines.
o Tasks:
1. Design tables for books, members, reservations, borrow transactions,
and fines.
2. Implement triggers to automatically apply fines if books are not
returned by the due date.
3. Write queries to list all overdue books and calculate the total fine for
each member.
4. Advanced: Create a stored procedure to process book reservations.
The procedure should update the availability of books based on
borrowings and reservations.
5. Concurrency: Handle concurrent reservations for the same book using
appropriate locking mechanisms or checks.
Objective: Design a system that tracks and analyzes sales data in real-time, providing
insights into sales performance.
Exercise:
o Scenario: You are tasked with building a database system to analyze real-time
sales data. This system should track products, customers, sales transactions,
and generate live reports.
o Tasks:
1. Design tables for sales, products, customers, and stores.
2. Implement a system that logs sales transactions as they happen, storing
details such as quantity, total price, and customer.
3. Write complex SQL queries to calculate "Total Sales by Region," "Top
Selling Products," and "Customer Purchase Behavior."
4. Advanced: Implement a trigger that automatically updates a "Sales
Dashboard" with aggregated sales statistics whenever a new sale is
added.
5. Real-Time Updates: Discuss how you would implement real-time
data aggregation (e.g., using materialized views or caching) for
efficient reporting.
Objective: Create a database for managing restaurant reservations, menus, and orders.
Exercise:
o Scenario: Create a database to manage restaurant reservations, menu items,
and customer orders. The system should track reservations, seating, and order
details.
o Tasks:
1. Design tables for reservations, customers, menu items, orders, and
payment transactions.
2. Implement relationships to ensure that reservations correspond to
specific customers and tables.
3. Write SQL queries to generate reports such as "Revenue by Table,"
"Menu Item Popularity," and "Reservations per Day."
4. Advanced: Implement a stored procedure to automatically send a
confirmation message to customers once their reservation is confirmed.
5. Concurrency: Discuss how you would handle concurrent reservations
for the same table during peak hours.
15. Database Design for a Healthcare System with Patient History
16. Database Design for a Ticketing System (e.g., Concerts, Sports Events)
Objective: Build a database to manage event ticket sales, seating arrangements, and
customer preferences.
Exercise:
o Scenario: You need to design a database for a ticketing system that handles
events, seating arrangements, ticket sales, and customer information.
o Tasks:
1. Design tables for events, tickets, customers, and seating arrangements.
2. Implement foreign key relationships to link ticket sales with events and
customers.
3. Write queries to generate reports such as "Total sales for a specific
event," "Customer ticket purchase history," and "Revenue per event."
4. Advanced: Create a stored procedure to automatically issue tickets and
reserve seats when a customer buys a ticket.
5. Concurrency: Implement a locking mechanism to prevent double-
booking of seats during high-demand periods.
Objective: Create a system that tracks student enrollments, courses, professors, and
grades.
Exercise:
o Scenario: Build a database for a university that tracks student enrollment,
courses, professors, and grades.
o Tasks:
1. Design tables for students, courses, professors, enrollments, and
grades.
2. Write queries to generate reports such as “Student grades by course,”
“Professors teaching multiple courses,” and “Students enrolled in
multiple courses.”
3. Implement a stored procedure to calculate final grades for students
based on their exam scores and participation.
4. Normalization: Normalize the schema to eliminate data redundancy
and ensure data integrity.
5. Concurrency: Implement a mechanism to handle concurrent
enrollments or course changes, ensuring that data integrity is
maintained.
Objective: Build a database for managing property listings, real estate agents, buyers,
and transactions.
Exercise:
o Scenario: Design a real estate management system to track property listings,
agents, buyers, and transactions.
o Tasks:
1. Design tables for properties, real estate agents, buyers, transactions,
and property types.
2. Write queries to generate reports such as “Most popular property
types,” “Average transaction value per agent,” and “Properties sold by
location.”
3. Implement a trigger to automatically update the status of a property
when a transaction is completed.
4. Advanced: Develop a stored procedure to calculate commission
payouts to agents based on the transaction value and agent’s share.
5. Performance: Optimize queries that calculate statistics for multiple
property types and regions.
Objective: Design a system for managing movie rentals, inventory, customers, and
rental history.
Exercise:
o Scenario: Create a database to manage movie rentals, inventory, and customer
data.
o Tasks:
1. Design tables for movies, customers, rentals, inventory, and payment
transactions.
2. Implement foreign key constraints and ensure data integrity between
tables like rentals and customers.
3. Write queries to track the "Top 10 most rented movies" and "Rental
history by customer."
4. Advanced: Develop a stored procedure to automatically apply rental
fees and due dates based on movie categories (e.g., new releases vs.
old movies).
5. Concurrency: Implement locking mechanisms to prevent double
rentals for the same movie during peak demand.
Objective: Build a database to manage auction listings, bids, and users in an online
auction platform.
Exercise:
o Scenario: Design a database for an online auction platform where users can
list items for auction and place bids.
o Tasks:
1. Design tables for users, auction listings, bids, and transactions.
2. Write queries to track the current highest bid for an item, the total
number of bids, and the winning bidder.
3. Advanced: Create a stored procedure to automatically close auctions
when the bidding period ends and declare the winner.
4. Implement a trigger to notify the user when they have been outbid on
an auction item.
5. Performance: Optimize queries related to auction history and user
bids to ensure quick response times during peak usage.
Objective: Build a system to manage ticket sales, train or bus schedules, and
customer bookings.
Exercise:
o Scenario: Create a database for a public transport system to manage ticket
bookings, schedules, and available seats.
o Tasks:
1. Design tables for customers, tickets, routes, vehicles (e.g., buses,
trains), and schedules.
2. Write SQL queries to track available seats for specific routes, and the
most popular travel times or routes.
3. Advanced: Develop a stored procedure to automatically assign seats
based on availability when a customer books a ticket.
4. Concurrency: Implement locking to prevent double-booking on
highly-demanded routes or times.
5. Optimization: Optimize queries to return real-time ticket availability
and price estimates quickly.