MySQL + SQL · Lesson 118

Hospital Database Project

About this Project

A Hospital Management database stores patients, doctors and appointments — a common DBMS mini-project.

Database Schema

CREATE TABLE doctors (doctor_id INT PRIMARY KEY, name VARCHAR(50), specialty VARCHAR(40));
CREATE TABLE patients (patient_id INT PRIMARY KEY, name VARCHAR(50), age INT, city VARCHAR(30));
CREATE TABLE appointments (appt_id INT PRIMARY KEY, patient_id INT, doctor_id INT, appt_date DATE,
  FOREIGN KEY(patient_id) REFERENCES patients(patient_id),
  FOREIGN KEY(doctor_id) REFERENCES doctors(doctor_id));

Useful Queries

-- appointments with patient and doctor names
SELECT p.name AS patient, d.name AS doctor, a.appt_date
FROM appointments a JOIN patients p ON a.patient_id=p.patient_id
                    JOIN doctors d ON a.doctor_id=d.doctor_id;

-- appointments per doctor
SELECT d.name, COUNT(*) AS total
FROM appointments a JOIN doctors d ON a.doctor_id=d.doctor_id
GROUP BY d.name;

Summary

  • This project shows a real, exam-ready database design with working queries.
  • Create the tables, insert sample data, and run each query to learn by doing.
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

WhatsApp