This document contains a student's submission for a database management systems course. It includes the student's name, roll number, subject, and submission date. The document then shows the normalization of a patient database from its initial form to third normal form through a series of transformations. It also includes 10 SQL queries over the normalized database table.
2. Patient
ID
Patient
Name
Address Appointment
Date
Doctor Dieses Fee Room Test
P-1 Sarfraz
Ahmad
13-B Shadman
Colony Gujrat
10-12-2017 Dr. Imran Blood
Pressure
1000 110 Blood Sugar
12-08-2017 Dr. Nasir Fever 850 115 ERCCI
05-04-2017 Dr. Imran Anxiety 110 ABL Mutation
01-02-2017 Dr.
Shahid
Blood
Pressure
1000 120 Blood Sugar
P-2 Shahid 7-A Marghzar
Colony Gujrat
10-12-2017 Dr. Nasir Fever 850 115 Blood Sugar
09-10-2017 Dr. Imran Anxiety 110 ERCCI
02-08-2017 Dr.
Shahid
Blood
Pressure
1000 120 ABL Mutation
1st
NORMAL FORM
P_ID P_Name Address Appointment
_Date
Doctor Dieses Fee Room_
no
Test
p-1 Sarfraz
Ahmad
13-B
Shadman
Colony
Gujrat
10-12-2017 Dr. Imran Blood
Pressure
1000 110 Blood
Sugar
p-1 Sarfraz
Ahmad
13-B
Shadman
Colony
Gujrat
12-08-2017 Dr. Nasir Fever 850 115 ERCCI
p-1 Sarfraz
Ahmad
13-B
Shadman
Colony
Gujrat
05-04-2017 Dr. Imran Anxiety 110 ABL
Mutation
p-1 Sarfraz
Ahmad
13-B
Shadman
Colony
Gujrat
01-02-2017 Dr.
Shahid
Blood
Pressure
1000 120 Blood
Sugar
p-2 Shahid 7-A
Marghzar
Colony
Gujrat
10-12-2017 Dr. Nasir Fever 850 115 Blood
Sugar
p-2 Shahid 7-A
Marghzar
Colony
Gujrat
09-10-2017 Dr. Imran Anxiety 110 ERCCI
p-2 Shahid 7-A
Marghzar
Colony
Gujrat
02-08-2017 Dr.
Shahid
Blood
Pressure
1000 120 ABL
Mutation
3. 2nd
NORMAL FORM
P_ID P_Name Address
p-1 Sarfraz
Ahmad
13-B
Shadman
Colony
Gujrat
p-2 Shahid 7-A
Marghzar
Colony
Gujrat
Appointment
_ID
Appointment
_Date
Doctor Dieses Fee Room_
no
Test P_ID
1 10-12-2017 Dr. Imran Blood
Pressure
1000 110 Blood
Sugar
p-1
2 12-08-2017 Dr. Nasir Fever 850 115 ERCCI p-1
3 05-04-2017 Dr. Imran Anxiety 110 ABL
Mutation
p-1
4 01-02-2017 Dr.
Shahid
Blood
Pressure
1000 120 Blood
Sugar
p-1
5 10-12-2017 Dr. Nasir Fever 850 115 Blood
Sugar
p-2
6 09-10-2017 Dr. Imran Anxiety 110 ERCCI p-2
7 02-08-2017 Dr.
Shahid
Blood
Pressure
1000 120 ABL
Mutation
p-2
3rd
NORMAL FORM
P_ID P_Name Address
p-1 Sarfraz
Ahmad
13-B
Shadman
Colony
Gujrat
p-2 Shahid 7-A
Marghzar
Colony
Gujrat
Doctor Doctor Room_no
4. ID Name
1 Dr. Imran 110
2 Dr. Nasir 115
3 Dr. Shahid 120
Dieses
ID
Dieses
Name
Fee
1 Blood
Pressure
1000
2 Fever 850
3 Anxiety 1000
Test ID Test
1 Blood
Sugar
2 ERCCI
3 ABL
Mutation
Q: Write Structure Query Language (SQL) queries for following question according to the
table obtained in 1NF. (Table’s name: Patient_Information).
1. Count total number of patient who are treated in the clinic.
2. Display only patientID, name and address for each patient. Record for each patient
shouldn’t be displayed more than once.
3. Display patient information for those patients who are treated as FREE. Patient
information should consist of patient’s tests and doctor.
4. Display the dieses having name started from “A” and treated as FREE.
5. Display the diagnosis’s names in descending order. Moreover show treatment facility for
each diagnosis, either it is free or paid.
6. Change the test of “ECCI” to “X-Rays”.
7. Insert a new record of Patient ID=P-3, Patient Name=Rizwan, Address=15-G, Gulberg,
Islamabad, Appointment Date=22-12-2017, Doctor=Dr.Imran, Dieses =Bone Fracture,
treatment=5000, room=130, test=X-Ray.
8. Add another column into table, named as dateOfBirth and data type as date.
9. Delete record of patient who paid maximum Fee.
10. Show information about patient ID=P-1 where he treated free.
5. SOLUTION:
1: select count(distinct P_ID) from Patient_Information;
2: Select distinct P_ID, P_Name, Address from Patient_Information;
3: Select Doctor, Test from Patient_Information where fee is NULL;
4: Select Dieses from Patient_Information where fee is NULL and Dieses like ‘A%’;
5: Select Doctor, Test, Room, Dieses from Patient_ Information order by Dieses desc;
6: Select Update Patient_ Information set Test=’X-Rays’ where Test = ‘ECCI’;
7: Insert into Patient_Information (P_ID,P_Name, Address , Appointment_Date, Doctor,
Dieses, treatment, room, Test) values ( p-3, Rizwan, 15-G, GulbergIslamabad, 22-12-
2017, Dr.Imran, Bone Fracture, 5000, 130, X-Ray);
8: Alter table patient_ Information add (Dob date);
9: Delete from Patient_Information where fee in(select max(fee) from Patient_Information);
10: select * from Patient_Information where P_ID=P-1 and fee is NULL;