0% found this document useful (0 votes)
14 views4 pages

ER Diagram For Hospital Management System

Uploaded by

Farhan Khurshid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

ER Diagram For Hospital Management System

Uploaded by

Farhan Khurshid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

ER Diagram for Hospital Management System:

| Hospital |

| hospital_id (PK) |

| name |

| address |

+---------------+------------------+

+---------------+ +---------------+ +----------------+

| Department | | Doctor | | Patient |

+---------------+ +---------------+ +----------------+

| department_id | | doctor_id (PK) | | patient_id (PK)|

| name | | name | | name |

| | | department_id | | address |

| || | | contact_number |

+---------------+ | | | |

| | | |

| | | |

+----------+------+ | | |

| | | | |

+----------------+ +------------------+ |

| Appointment | | Prescription | |

+----------------+ +------------------+ |

| appointment_id | | prescription_id | |

| doctor_id | | patient_id | |
| patient_id | | doctor_id | |

| date | | date | |

| time | | medicine | |

+----------------+ +------------------+ |

SQL Queries:

1 Create tables:

CREATE TABLE Hospital (

Hospital_id INT PRIMARY KEY,

Name VARCHAR(255),

Address VARCHAR(255)

);

CREATE TABLE Department (

Department_id INT PRIMARY KEY,

Name VARCHAR(255)

);

CREATE TABLE Doctor (

Doctor_id INT PRIMARY KEY,

Name VARCHAR(255),

Department_id INT,

FOREIGN KEY (department_id) REFERENCES Department(department_id)

);

CREATE TABLE Patient (

Patient_id INT PRIMARY KEY,

Name VARCHAR(255),

Address VARCHAR(255),
Contact_number VARCHAR(20)

);

CREATE TABLE Appointment (

Appointment_id INT PRIMARY KEY,

Doctor_id INT,

Patient_id INT,

Date DATE,

Time TIME,

FOREIGN KEY (doctor_id) REFERENCES Doctor(doctor_id),

FOREIGN KEY (patient_id) REFERENCES Patient(patient_id)

);

CREATE TABLE Prescription (

Prescription_id INT PRIMARY KEY,

Doctor_id INT,

Patient_id INT,

Date DATE,

Medicine VARCHAR(255),

FOREIGN KEY (doctor_id) REFERENCES Doctor(doctor_id),

FOREIGN KEY (patient_id) REFERENCES Patient(patient_id)

);

2 Insert data into tables:

INSERT INTO Hospital (hospital_id, name, address)

VALUES (1, ‘ABC Hospital’, ‘123 Main St’);

INSERT INTO Department (department_id, name)

VALUES (1, ‘Cardiology’);


INSERT INTO Doctor (doctor_id, name, department_id)

VALUES (1, ‘Dr. John Doe’, 1);

INSERT INTO Patient (patient_id, name, address, contact_number)

VALUES (1, ‘Jane Smith’, ‘456 Elm St’, ‘555-1234’);

INSERT INTO Appointment (appointment_id, doctor_id, patient_id, date, time)

VALUES (1, 1, 1, ‘2023-05-18’, ’10:00:00’);

INSERT INTO Prescription (prescription_id, doctor_id, patient_id, date, medicine)

VALUES (1, 1, 1, ‘2023-05-18’, ‘Medicine A’);

3 Retrieve data from tables:

Retrieve all hospitals:

SELECT * FROM Hospital;

Retrieve all departments:

SELECT * FROM Department;

Retrieve all prescriptions:

You might also like