Programming Assign. Unit 7
Programming Assign. Unit 7
Course: CS 2203
Using the Specialty, Doctor, Patient, Appointment, Allergy, PatientAllergy, Medicine, and
PatientMedicine relations created for Hospital System database in the Unit 5 Programming
Assignment, populate them with data using the following information in the tables. If your
relations have additional attributes that are not included in the following table list, then add
appropriate values to populate your relations with data.
Assignment Instructions:
Provide all of the SQL statements required to create the relations
Populate the relations with data (using SQL insert statements) by using information in
below tables
Issue a select statement for each relation to retrieve data in relations
Include both the select statement and the output of the select statement (using a
screenshot of your database’s output) that shows the contents of each relation
1- Doctor:
CREATE Statement:
CREATE TABLE Doctor(Varchar(10), Name Varchar(50) Not NULL, Phone
Varchar(15), SpecialityNumber INT NOT NULL , Suprvisor INT NOT NULL,
constraint specikey foreign key (SpecialityNumber) references
Speciality(SpecialityNumber), constraint suprvisorkey foreign key (Suprvisor)
references Doctor(DoctorID) , primary key (doctorID));
INSERT Statement:
Insert Into Doctor (DoctorID, Name, Phone, SpecialtyNumber, Supervisor) Values
('D1','Doctor Karen','555-1212','S6','');
Insert Into Doctor (DoctorID, Name, Phone, SpecialtyNumber, Supervisor) Values
('D2','Doctor John','555-2934','S2','D1');
Insert Into Doctor (DoctorID, Name, Phone, SpecialtyNumber, Supervisor) Values
('D3','Doctor Robert','555-6723','S6','D1');
Insert Into Doctor (DoctorID, Name, Phone, SpecialtyNumber, Supervisor) Values
('D4','Doctor David','555-1745','S4','D1');
Insert Into Doctor (DoctorID, Name, Phone, SpecialtyNumber, Supervisor) Values
('D5','Doctor Mary','555-6565','S5','D1');
Insert Into Doctor (DoctorID, Name, Phone, SpecialtyNumber, Supervisor) Values
('D6','Doctor Linda','555-4889','S1','D1');
Insert Into Doctor (DoctorID, Name, Phone, SpecialtyNumber, Supervisor) Values
('D7','Doctor Susan','555-4581','S3','D1');
Insert Into Doctor (DoctorID, Name, Phone, SpecialtyNumber, Supervisor) Values
('D8','Doctor Zeynep','555-7891','S4','D1');
Insert Into Doctor (DoctorID, Name, Phone, SpecialtyNumber, Supervisor) Values
('D9','Doctor Mat','555-7791','S1','D1');
Computer Science
Course: CS 2203
2- Patient:
CREATE Statement:
CREATE TABLE Patient(PatientID Varchar(10), Name Varchar(50) NOT NULL, Phone
Varchar(15), Email Varchar(35) null, Address Varchar(120) NOT NULL, AddedDate
date NOT NULL, DoctorID Varchar(10) NOT NULL, constraint doctorForeign foreign
key (DoctorID) references Doctor(DoctorID), primary key(PatientID));
INSERT Statement:
Insert Into Patient (PatientID, DoctorID, Name, Phone, Email, Address, AddedDate) Values
('P1','D2','Patient Dana','444-1212','P1@email.com','123 Home St.','2019-2-1');
Insert Into Patient (PatientID, DoctorID, Name, Phone, Email, Address, AddedDate) Values
('P2','D7','Patient Harry','444-2934','P2@email.com','3435 Main St.','2011-7-13');
Insert Into Patient (PatientID, DoctorID, Name, Phone, Email, Address, AddedDate) Values
('P3','D6','Patient Karl','444-6723','P3@email.com','2176 Baker St.','2009-5-10');
Computer Science
Course: CS 2203
Insert Into Patient (PatientID, DoctorID, Name, Phone, Email, Address, AddedDate) Values
('P4','D2','Patient Sid','444-1745','P4@email.com','176 Right St.','2010-6-20');
Insert Into Patient (PatientID, DoctorID, Name, Phone, Email, Address, AddedDate) Values
('P5','D8','Patient Marry','444-6565','P5@email.com','435 Main St.','2014-5-18');
Insert Into Patient (PatientID, DoctorID, Name, Phone, Email, Address, AddedDate) Values
('P6','D6','Patient Kim','444-4889','P6@email.com','34 Home St.','2018-3-15');
Insert Into Patient (PatientID, DoctorID, Name, Phone, Email, Address, AddedDate) Values
('P7','D4','Patient Susan','444-4581','P7@email.com','65 Water St.','2011-9-7');
Insert Into Patient (PatientID, DoctorID, Name, Phone, Email, Address, AddedDate) Values
('P8','D3','Patient Sam','444-7891','P8@email.com','23 Hill Drive','2010-11-23');
Insert Into Patient (PatientID, DoctorID, Name, Phone, Email, Address, AddedDate) Values
('P9','D5','Patient Peter','444-7791','P9@email.com','12 River St.','2008-2-1');
Insert Into Patient (PatientID, DoctorID, Name, Phone, Email, Address, AddedDate) Values
('P10','D7','Patient Nick','123-1212','P10@email.com','335 Bay St.','2011-7-13');
Insert Into Patient (PatientID, DoctorID, Name, Phone, Email, Address, AddedDate) Values
('P11','D9','Patient Kyle','123-2934','P11@email.com','216 Baker St.','2016-5-10');
Insert Into Patient (PatientID, DoctorID, Name, Phone, Email, Address, AddedDate) Values
('P12','D9','Patient Garcia','123-6723','P12@email.com','176 Right St.','2010-6-20');
Insert Into Patient (PatientID, DoctorID, Name, Phone, Email, Address, AddedDate) Values
('P13','D4','Patient Alicia','123-1745','P13@email.com','823 Left St.','2015-5-18');
Insert Into Patient (PatientID, DoctorID, Name, Phone, Email, Address, AddedDate) Values
('P14','D4','Patient Dan','123-6565','P14@email.com','534 High St.','2018-3-15');
Computer Science
Course: CS 2203
3- Appointment:
CREATE Statement:
CREATE TABLE Appointment(AppointmentID Varchar(10) PRIMARY KEY,
DoctorID Varchar(10) Not NULL, PatientID Varchar(10) Not NULL,
AppointmentDate date Not NULL,BloodPressure INT, Weight Double,
TreatmentNotes Varchar(100),constraint doctorAppointed foreign key (DoctorID)
references Doctor(DoctorID), constraint patientApointed foreign key (PatientID)
references Patient(PatientID));
INSERT Statement:
Insert Into Appointment (AppointmentID, PatientID, DoctorID, AppointmentDate,
BloodPressure, Weight, TreatmentNotes) Values ('A1','P1','D2','2019-7-1','80','65','Dream to
success');
Insert Into Appointment (AppointmentID, PatientID, DoctorID, AppointmentDate,
BloodPressure, Weight, TreatmentNotes) Values ('A2','P13','D4','2019-1-4','77','88','Good
heart rate');
Computer Science
Course: CS 2203
4- Specialty:
CREATE Statement:
CREATE TABLE Speciality(SpecialityNumber Varchar(10)
PRIMARY KEY, SpecialiatyName Varchar(50) NOT NULL);
INSERT Statement:
Insert Into Speciality (SpecialityNumber, SpecialiatyName) Values ('S1','Dermatology');
Insert Into Speciality (SpecialityNumber, SpecialiatyName) Values ('S2','Psychiatry');
Insert Into Speciality (SpecialityNumber, SpecialiatyName) Values ('S3','Oncology');
Insert Into Speciality (SpecialityNumber, SpecialiatyName) Values ('S4','Cardiology');
Insert Into Speciality (SpecialityNumber, SpecialiatyName) Values ('S5','Urology');
Insert Into Speciality (SpecialityNumber, SpecialiatyName) Values ('S6','Pediatrics');
Computer Science
Course: CS 2203
5- PatientMedicine:
CREATE Statement:
CREATE TABLE PatientMedicine(AppointmentID Varchar(10), MedicineID
Varchar(10), Primary key (AppointmentID, MedicineID),constraint Apointrefer
foreign key (AppointmentID) references Appointment(AppointmentID),constraint
patmed foreign key (MedicineID) references Medicine(MedicineID));
INSERT Statement:
Insert Into PatientMedicine (AppointmentID, MedicineID) Values('A15','M1');
Insert Into PatientMedicine (AppointmentID, MedicineID) Values('A2','M6');
Insert Into PatientMedicine (AppointmentID, MedicineID) Values('A8','M3');
Insert Into PatientMedicine (AppointmentID, MedicineID) Values('A6','M3');
Insert Into PatientMedicine (AppointmentID, MedicineID) Values('A15','M2');
Insert Into PatientMedicine (AppointmentID, MedicineID) Values('A10','M6');
Insert Into PatientMedicine (AppointmentID, MedicineID) Values('A10','M2');
Insert Into PatientMedicine (AppointmentID, MedicineID) Values('A4','M5');
Insert Into PatientMedicine (AppointmentID, MedicineID) Values('A3','M5');
Insert Into PatientMedicine (AppointmentID, MedicineID) Values('A1','M2');
Computer Science
Course: CS 2203
6- Medicine:
CREATE Statement:
CREATE TABLE Medicine(MedicineID varchar(10) PRIMARY KEY,
MedicineName varchar(150) Not NULL);
INSERT Statement:
7- PatientAllergy:
CREATE Statement:
CREATE TABLE PatientAllergy(PatientID varchar(10), AllergyID varchar(10),
Primary key (PatientID, AllergyID), constraint patientKey foreign key (PatientID)
references Patient(PatientID), constraint allergyKey foreign key (AllergyID)
references Allergy(AllergyID));
INSERT Statement:
Insert Into PatientAllergy (AllergyID, PatientID) Values('AL4','P1');
Insert Into PatientAllergy (AllergyID, PatientID) Values('AL2','P13');
Insert Into PatientAllergy (AllergyID, PatientID) Values('AL3','P11');
Insert Into PatientAllergy (AllergyID, PatientID) Values('AL4','P7');
Insert Into PatientAllergy (AllergyID, PatientID) Values('AL5','P9');
Insert Into PatientAllergy (AllergyID, PatientID) Values('AL1','P3');
Computer Science
Course: CS 2203
8- Allergy:
CREATE Statement:
CREATE TABLE Allergy(AllergyID varchar(10) PRIMARY KEY, AllergyName
varchar(150) Not NULL);
INSERT Statement: