Practical SQL Task: Hospital Management System
Scenario:
You have been hired as a database administrator for a hospital. Your task is to design and
implement a Hospital Management System (HMS) using MySQL. The system should efficiently
manage patient records, doctor assignments, medical history, and billing.
Task Breakdown:
1. Database Creation and Table Design
Create a database named HospitalDB.
Design and create tables for managing hospital operations with the following structure:
Tables:
1. Patients
PatientID (Primary Key)
FirstName
LastName
DOB (Date of Birth)
Gender
PhoneNumber
Email
Address
BloodType
InsuranceNumber
2. Doctors
DoctorID (Primary Key)
FirstName
LastName
Specialization
PhoneNumber
Email
Department
3. Appointments
AppointmentID (Primary Key)
PatientID (Foreign Key references Patients.PatientID)
DoctorID (Foreign Key references Doctors.DoctorID)
AppointmentDate
Diagnosis
Prescription
ConsultationFee
4. MedicalHistory
HistoryID (Primary Key)
PatientID (Foreign Key references Patients.PatientID)
DoctorID (Foreign Key references Doctors.DoctorID)
DateRecorded
ConditionDiagnosed
TreatmentGiven
5. Billing
BillID (Primary Key)
PatientID (Foreign Key references Patients.PatientID)
AmountDue
PaymentStatus (Paid, Unpaid, Pending)
DateOfBill
PaymentMethod
---
2. Data Insertion
Insert at least 10 patients, 5 doctors, and 15 appointments.
Add 5 medical history records per patient.
Generate billing records for at least 10 patients.
---
3. Querying the Database
Basic Queries:
1. Retrieve all appointments for a given patient, including the doctor's name and specialization.
2. Find all patients treated by a specific doctor.
3. Get a list of unpaid bills.
4. Count the number of patients each doctor has treated.
Advanced Queries:
5. Find the total revenue generated by consultations.
6. Retrieve patients who have had more than three appointments in the last year.
7. Get a list of doctors with the highest number of appointments.
8. Identify patients who have been diagnosed with Diabetes at least twice.
Modification Queries:
9. Update the consultation fee for all doctors specializing in Cardiology.
10. Delete records of patients who haven't had an appointment in the last 5 years.