Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Database Management Systems (DBMS) Course Code: CT-261

Name: Abbas Raza


Roll No: CT-21075 (SEC-B)
Department: CSIT (Second Year)

“ASSIGNMENT #2”

“Hospital Management System”

Generated SQL:
CREATE TABLE Patient
(
ID INT NOT NULL,
Name INT NOT NULL,
Address INT NOT NULL,
PRIMARY KEY (ID)
);

CREATE TABLE Prescription


(
ID INT NOT NULL,
fk_Treatment-ID INT NOT NULL,
Medication_Name INT NOT NULL,
Dosage INT NOT NULL,
Start_Date INT NOT NULL,
End_Date INT NOT NULL,
PRIMARY KEY (ID)
);

CREATE TABLE Department


(
Name INT NOT NULL,
ID INT NOT NULL,
PRIMARY KEY (ID)
);

CREATE TABLE Insurance


(
fk_Patient_ID INT NOT NULL,
Pa ge 1|6
Database Management Systems (DBMS) Course Code: CT-261

Policy_Number INT NOT NULL,


fk_Diagnosis_ID INT NOT NULL,
ID INT NOT NULL,
ID INT NOT NULL,
PRIMARY KEY (ID),
FOREIGN KEY (ID) REFERENCES Patient(ID)
);

CREATE TABLE Payment


(
ID INT NOT NULL,
fk_Treatment_ID INT NOT NULL,
Amount INT NOT NULL,
Payment_Date INT NOT NULL,
PRIMARY KEY (ID)
);

CREATE TABLE Patient_Phone


(
Phone INT NOT NULL,
ID INT NOT NULL,
PRIMARY KEY (Phone, ID),
FOREIGN KEY (ID) REFERENCES Patient(ID)
);

CREATE TABLE Patient_Email


(
Email INT NOT NULL,
ID INT NOT NULL,
PRIMARY KEY (Email, ID),
FOREIGN KEY (ID) REFERENCES Patient(ID)
);

CREATE TABLE Department_Phone


(
Phone INT NOT NULL,
ID INT NOT NULL,
PRIMARY KEY (Phone, ID),
FOREIGN KEY (ID) REFERENCES Department(ID)
);

CREATE TABLE Department_Email


(
Email INT NOT NULL,
ID INT NOT NULL,
PRIMARY KEY (Email, ID),
FOREIGN KEY (ID) REFERENCES Department(ID)
);

CREATE TABLE Doctor


(
Pa ge 2|6
Database Management Systems (DBMS) Course Code: CT-261

ID INT NOT NULL,


Specialization INT NOT NULL,
Name INT NOT NULL,
ID INT NOT NULL,
PRIMARY KEY (ID),
FOREIGN KEY (ID) REFERENCES Department(ID)
);

CREATE TABLE Nurse


(
ID INT NOT NULL,
Name INT NOT NULL,
fk_Wards_ID INT NOT NULL,
ID INT NOT NULL,
PRIMARY KEY (ID),
FOREIGN KEY (ID) REFERENCES Department(ID)
);

CREATE TABLE Appoinment


(
fk_Doctor_ID INT NOT NULL,
fk_Patient_ID INT NOT NULL,
ID INT NOT NULL,
Date INT NOT NULL,
Time INT NOT NULL,
ID INT NOT NULL,
ID INT NOT NULL,
PRIMARY KEY (ID),
FOREIGN KEY (ID) REFERENCES Patient(ID),
FOREIGN KEY (ID) REFERENCES Doctor(ID)
);

CREATE TABLE Wards


(
ID INT NOT NULL,
Name INT NOT NULL,
fk_Department_ID INT NOT NULL,
ID INT NOT NULL,
ID INT NOT NULL,
PRIMARY KEY (ID),
FOREIGN KEY (ID) REFERENCES Nurse(ID),
FOREIGN KEY (ID) REFERENCES Department(ID)
);

CREATE TABLE Treatment


(
ID INT NOT NULL,
fk_Diagnosis_ID INT NOT NULL,
Treatment_Type INT NOT NULL,
Start_Date INT NOT NULL,
End_Date INT NOT NULL,
Pa ge 3|6
Database Management Systems (DBMS) Course Code: CT-261

Cost INT NOT NULL,


ID INT NOT NULL,
ID INT NOT NULL,
PRIMARY KEY (ID),
FOREIGN KEY (ID) REFERENCES Prescription(ID),
FOREIGN KEY (ID) REFERENCES Payment(ID)
);

CREATE TABLE Bed


(
ID INT NOT NULL,
Bed_Number INT NOT NULL,
fk_Ward_ID INT NOT NULL,
ID INT NOT NULL,
PRIMARY KEY (ID),
FOREIGN KEY (ID) REFERENCES Wards(ID)
);

CREATE TABLE Doctor_Phone


(
Phone INT NOT NULL,
ID INT NOT NULL,
PRIMARY KEY (Phone, ID),
FOREIGN KEY (ID) REFERENCES Doctor(ID)
);

CREATE TABLE Doctor_Email


(
Email INT NOT NULL,
ID INT NOT NULL,
PRIMARY KEY (Email, ID),
FOREIGN KEY (ID) REFERENCES Doctor(ID)
);

CREATE TABLE Nurse_Email


(
Email INT NOT NULL,
ID INT NOT NULL,
PRIMARY KEY (Email, ID),
FOREIGN KEY (ID) REFERENCES Nurse(ID)
);

CREATE TABLE Nurse_Phone


(
Phone INT NOT NULL,
ID INT NOT NULL,
PRIMARY KEY (Phone, ID),
FOREIGN KEY (ID) REFERENCES Nurse(ID)
);

CREATE TABLE Diagnosis


Pa ge 4|6
Database Management Systems (DBMS) Course Code: CT-261

(
ID INT NOT NULL,
fk_Patient_ID INT NOT NULL,
Diagnosis_Type INT NOT NULL,
Diagnosis_Date INT NOT NULL,
ID INT NOT NULL,
ID INT NOT NULL,
PRIMARY KEY (ID),
FOREIGN KEY (ID) REFERENCES Patient(ID),
FOREIGN KEY (ID) REFERENCES Treatment(ID)
);

Logical ERD:

Referential Integrity:
The following referential integrity constraints will apply on the Hospital Management System:
• The Appointment table has a foreign key referencing the Patient table, which ensures that
a patient cannot have an appointment unless they exist in the Patient table.
• The Appointment table has a foreign key referencing the Doctor table, which ensures that
an appointment cannot be made with a doctor that does not exist in the Doctor table.

Pa ge 5|6
Database Management Systems (DBMS) Course Code: CT-261

• The Appointment table has a foreign key referencing the Department table, which
ensures that an appointment cannot be made in a department that does not exist in the
Department table.
• The Diagnosis table has a foreign key referencing the Patient table, which ensures that a
diagnosis cannot be associated with a patient that does not exist in the Patient table.
• The Prescription table has a foreign key referencing the Treatment table, which ensures
that a prescription cannot be associated with a treatment that does not exist in the
Treatment table.
• The Treatment table has a foreign key referencing the Diagnosis table, which ensures that
a treatment cannot be associated with a diagnosis that does not exist in the Diagnosis
table.
• The Ward table has a foreign key referencing the Department table, which ensures that a
ward cannot belong to a department that does not exist in the Department table.
• The Bed table has a foreign key referencing the Ward table, which ensures that a bed
cannot belong to a ward that does not exist in the Ward table.
• The Insurance table has a foreign key referencing the Patient table, which ensures that an
insurance policy cannot be associated with a patient that does not exist in the Patient
table.
• The Payment table has a foreign key referencing the Treatment table, which ensures that
a payment cannot be associated with a treatment that does not exist in the Treatment
table.

Pa ge 6|6

You might also like