Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
749 views

Programming Assign. Unit 7

The document provides SQL statements to create and populate tables in a Hospital database system with sample data. The tables include: Doctor, Patient, Appointment, and Specialty. CREATE statements define the structure of each table and INSERT statements add multiple records to each table with sample data. In total, over 50 records are added to the four tables to demonstrate populating the relations.

Uploaded by

Majd Haddad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
749 views

Programming Assign. Unit 7

The document provides SQL statements to create and populate tables in a Hospital database system with sample data. The tables include: Doctor, Patient, Appointment, and Specialty. CREATE statements define the structure of each table and INSERT statements add multiple records to each table with sample data. In total, over 50 records are added to the four tables to demonstrate populating the relations.

Uploaded by

Majd Haddad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Computer Science

Course: CS 2203

Programming Assign. Unit 7

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

Insert Into Appointment (AppointmentID, PatientID, DoctorID, AppointmentDate,


BloodPressure, Weight, TreatmentNotes) Values ('A3','P11','D9','2019-3-22','82','95','Many
spots');
Insert Into Appointment (AppointmentID, PatientID, DoctorID, AppointmentDate,
BloodPressure, Weight, TreatmentNotes) Values ('A4','P7','D4','2020-2-1','85','74','Fast heart
rate');
Insert Into Appointment (AppointmentID, PatientID, DoctorID, AppointmentDate,
BloodPressure, Weight, TreatmentNotes) Values ('A5','P9','D5','2019-4-13','75','56','Reports
checked');
Insert Into Appointment (AppointmentID, PatientID, DoctorID, AppointmentDate,
BloodPressure, Weight, TreatmentNotes) Values ('A6','P3','D6','2019-11-12','81','96','Sun
light spots');
Insert Into Appointment (AppointmentID, PatientID, DoctorID, AppointmentDate,
BloodPressure, Weight, TreatmentNotes) Values ('A7','P10','D7','2020-1-29','80','87','Early
treatment');
Insert Into Appointment (AppointmentID, PatientID, DoctorID, AppointmentDate,
BloodPressure, Weight, TreatmentNotes) Values ('A8','P9','D5','2019-8-12','86','92','Much
better');
Insert Into Appointment (AppointmentID, PatientID, DoctorID, AppointmentDate,
BloodPressure, Weight, TreatmentNotes) Values ('A9','P14','D4','2019-5-18','75','75','Good
heart rate');
Insert Into Appointment (AppointmentID, PatientID, DoctorID, AppointmentDate,
BloodPressure, Weight, TreatmentNotes) Values ('A10','P8','D3','2019-11-18','76','79','New
teeth');
Insert Into Appointment (AppointmentID, PatientID, DoctorID, AppointmentDate,
BloodPressure, Weight, TreatmentNotes) Values ('A11','P11','D9','2019-6-22','78','71','Much
better');
Insert Into Appointment (AppointmentID, PatientID, DoctorID, AppointmentDate,
BloodPressure, Weight, TreatmentNotes) Values ('A12','P2','D7','2020-2-21','82','86','Early
treatment');
Insert Into Appointment (AppointmentID, PatientID, DoctorID, AppointmentDate,
BloodPressure, Weight, TreatmentNotes) Values ('A13','P4','D2','2019-8-17','81','101','Bad
dreams');
Insert Into Appointment (AppointmentID, PatientID, DoctorID, AppointmentDate,
BloodPressure, Weight, TreatmentNotes) Values ('A14','P6','D6','2019-6-27','79','49','Sun
light spots');
Insert Into Appointment (AppointmentID, PatientID, DoctorID, AppointmentDate,
BloodPressure, Weight, TreatmentNotes) Values ('A15','P10','D7','2020-7-29','80','83','Early
treatment');
Insert Into Appointment (AppointmentID, PatientID, DoctorID, AppointmentDate,
BloodPressure, Weight, TreatmentNotes) Values ('A16','P7','D4','2020-8-1','78','79','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:

Insert Into Medicine (MedicineID, MedicineName) Values('M1','Ativan');


Insert Into Medicine (MedicineID, MedicineName) Values('M2','Ibuprofen');
Insert Into Medicine (MedicineID, MedicineName) Values('M3','Omeprazole ');
Insert Into Medicine (MedicineID, MedicineName) Values('M4','Metoprolol ');
Insert Into Medicine (MedicineID, MedicineName) Values('M5','Azithromycin ');
Insert Into Medicine (MedicineID, MedicineName) Values('M6','Codeine ');
Computer Science
Course: CS 2203
Computer Science
Course: CS 2203

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:

Insert Into Allergy (AllergyID, AllergyName) Values('AL1','Drug ');


Insert Into Allergy (AllergyID, AllergyName) Values('AL2','Food');
Insert Into Allergy (AllergyID, AllergyName) Values('AL3','Skin');
Insert Into Allergy (AllergyID, AllergyName) Values('AL4','Asthma ');
Insert Into Allergy (AllergyID, AllergyName) Values('AL5','Rhinitis');

You might also like