SlideShare a Scribd company logo
1 of 45
Download to read offline
Lab Project
A Hospital Database
Kingsley Usen
DBST651, Fall 2016
Submitted To
Graduate School
University of Maryland University College
Date: November 27, 2016
Statement of Work (SOW)
Kingsley Usen
DBST 651, FALL 2016
Overview:
I will create a database to keep track of patient data for a medical facility. This database will aid
in easing the flow of operations at a medical facility and provides immediate information to
doctors and nurses regarding the condition of a patient
Purpose and Objective:
The database will enable a nurse to enter and store a patient charts and histories during a
particular trip to the clinic. It stores the patient’s first and last name, age, symptoms,
prescriptions for the patient, and the date the patient is admitted into the clinic. This database
also keeps track of the doctors and nurses that attend to a particular patient as well as the patient
diagnosis from the doctor. The charts from the nurse is used to update the doctor on the condition
of the patient which in turn assists the doctor(s) in performing adequate diagnosis. The
information stored in this database would be used to efficiently track the patients that are treated
at the clinic, the nurse charts and history of patient’s symptoms, the doctors’ diagnosis of the
patient and the date a patient gets admitted and checked out of the clinic.
Diagram Tool:
ER Assistant
Database:
Oracle 11g, using Virtual Desktop Applications (VDA)
Hardware and Software:
UMUC (VDA) Intel(R) Core(TM). Operating system is Windows
DDL and DML:
SQL (Structured Query Language) will be used to create the DDL and DML scripts. SQL would
be used to translate the information captured using the ER Assistant, in an ER diagram, into
database table creation scripts for my DDL scripts. This diagram contains the various entities,
attributes and relationship that exist in this database. SQL would also be used to insert rows of
data or record into the database tables for my DML scripts. It would also be used to retrieve or
update a record
Entity Description
Entities Description
PATIENT Entity Name: Patient
Entity Description: patients who get treated in the hospital
Main attributes of Patient:
Attribute Name: Patient _ID
Attribute Description: patient Identification primary identification
Attribute Name: Patient _FN
Attribute Description: patient first name
Assistance/receives assistance
Assigned/gets assigned
Assignment
Assignment_ID
Nurse_ID_FK
Doctor_ID_FK
Assignment_Date
Assignment_Cap
Medicated/receives medecine
Prescribes/prescribes medication
Treats/treats patients
Analysis/charts the patient
Prescription
Prescription_ID
Doctor_ID_FK
Patient_ID_FK
Prescription_check
Prescription_Date
Prescription_Note
Doctor
Doctor_ID
Doctor_FN
Doctor_LN
Doctor_Phone
Doctor_SSN
Patient
Patient_ID
Patient_FN
Patient_LN
Notes
Doctor_ID_FK
Nurse_ID_FK
Nurse
Nurse_ID
Nurse_FN
Nurse_LN
Nurse_Phone
Nurse_SSN
Attribute Name: Patient _LN
Attribute Description: patient last name
Attribute Name: Notes
Attribute Description: symptoms of patient
Attribute Name: Doctor_ID_FK
Attribute Description: doctor identification foreign key
Attribute Name: Nurse_ID_FK
Attribute Description: nurse identification foreign key
DOCTOR Entity Name: Doctor
Entity Description: doctors who treat patients at the hospital
Main attributes of Doctor:
Attribute Name: Doctor _ID
Attribute Description: doctor identification primary key
Attribute Name: Doctor _FN
Attribute Description: doctor first name
Attribute Name: Doctor _LN
Attribute Description: doctor last name
Attribute Name: Doctor _Phone
Attribute Description: doctor phone number
Attribute Name: Doctor _SSN
Attribute Description: doctor social security number
NURSE Entity Name: Nurse
Entity Description: nurses who treat patients
Main attributes of Nurse:
Attribute Name: Nurse _ID
Attribute Description: nurse identification primary key
Attribute Name: Nurse _FN
Attribute Description: nurse first name
Attribute Name: Nurse _LN
Attribute Description: nurse last name
Attribute Name: Nurse _Phone
Attribute Description: nurse phone number
Attribute Name: Nurse _SSN
Attribute Description: nurse social security number
PRESCRIPTION Entity Name: Prescription
Entity Description: prescriptions for patients in the hospital
Main attributes of Prescription:
Attribute Name: Prescription _ID
Attribute Description: prescription identification primary key
Attribute Name: Doctor_ID_FK
Attribute Description: doctor identification foreign key
Attribute Name: Patient_ID_FK
Attribute Description: patient identification foreign key
Attribute Name: Prescription_Check
Attribute Description: checks the availability of prescriptions
Attribute Name: Prescription_Note
Attribute Description: lists the prescribed drugs separated by a delimiter
Attribute Name: Prescription_Date
Attribute Description: date a prescription was written
ASSIGNMENT Entity Name: Assignment
Entity Description: assignments of nurses to doctors at the hospital
Main attributes of Assignment:
Attribute Name: Assignment _ID
Attribute Description: assignment identification primary key
Attribute Name: Nurse_ID_FK
Attribute Description: nurse identification foreign key
Attribute Name: Doctor_ID_FK
Attribute Description: doctor identification foreign key
Attribute Name: Assignment_Date
Attribute Description: assignment date
Attribute Name: Assignment_Cap
Attribute Description: assignment capacity
Entity Relationship
Relationship: works between PATIENT and PRESCRIPTION
Cardinality/Business rule: a patient can receive zero to many prescriptions, a prescription is received by
one and only one patient
Relationship: works between DOCTOR and PATIENT
Cardinality/Business rule: a doctor can treat zero to many patients, a patient gets treated by one and
only one doctor
Relationship: works between DOCTOR and PRESCRIPTION
Cardinality/Business rule: a doctor can prescribe zero to many prescriptions, a prescription gets
prescribed by one and only one doctor
Relationship: works between NURSE and ASSIGNMENT
Cardinality/Business rule: a nurse can have zero to many assignments, an assignment is reserved for
one and only one nurse
Relationship: works between DOCTOR and ASSIGNMENT
Cardinality/Business rule: a doctor receives assistance from zero to many assigned nurses, an assigned
nurse provides assistance to one and only one doctor
Assumptions
1. A patient is only assigned one doctor throughout the duration of stay at this hospital
2. There is a cap at how many nurses can get assigned to a doctor at any time (maximum is 4).
3. The Assignment_Cap attribute in Assignment entity checks this value. If valid, then assignments
can be made
DDL (Data Definition Language)
REM ***************************************************************************
REM File: CreateHealthSystem.sql
REM Description: Used for creating the objects and loading data into
REM the Health System schema
REM Created: November 13, 2016
REM ****************************************************************************
PROMPT Dropping HealthSystem schema objects
REM === Drop Table ===
DROP TABLE PATIENT CASCADE CONSTRAINTS;
DROP TABLE PRESCRIPTION CASCADE CONSTRAINTS;
DROP TABLE DOCTOR CASCADE CONSTRAINTS;
DROP TABLE NURSE CASCADE CONSTRAINTS;
DROP TABLE ASSIGNMENT CASCADE CONSTRAINTS;
REM === Drop Sequences ===
DROP SEQUENCE PATIENT_ID_SEQ;
DROP SEQUENCE DOCTOR_ID_SEQ;
DROP SEQUENCE NURSE_ID_SEQ;
DROP SEQUENCE PRESCRIPTION_ID_SEQ;
DROP SEQUENCE ASSIGNMENT_ID_SEQ;
PROMPT Creating Table 'NURSE'
CREATE TABLE NURSE
(NURSE_ID NUMBER(8,0)
,NURSE_FN VARCHAR2(25)
,NURSE_LN VARCHAR2(25)
,NURSE_PHONE VARCHAR2(15)
,NURSE_SSN VARCHAR2(11)
,CREATED_BY VARCHAR2(30)
,CREATED_DATE DATE
,MODIFIED_BY VARCHAR2(30)
,MODIFIED_DATE DATE
)
/
COMMENT ON TABLE NURSE IS 'Profile information for a nurse.'
/
COMMENT ON COLUMN NURSE.NURSE_ID IS 'The unique ID for a nurse.'
/
COMMENT ON COLUMN NURSE.NURSE_FN IS 'This nurse''s first name.'
/
COMMENT ON COLUMN NURSE.NURSE_LN IS 'The nurse''s last name.'
/
COMMENT ON COLUMN NURSE.NURSE_PHONE IS 'The nurse''s phone number.'
/
COMMENT ON COLUMN NURSE.NURSE_SSN IS 'The nurse''s social security number.'
/
COMMENT ON COLUMN NURSE.CREATED_BY IS 'Audit column - indicates user who inserted
data.'
/
COMMENT ON COLUMN NURSE.CREATED_DATE IS 'Audit column - indicates date of insert.'
/
COMMENT ON COLUMN NURSE.MODIFIED_BY IS 'Audit column - indicates who made last
update.'
/
COMMENT ON COLUMN NURSE.MODIFIED_DATE IS 'Audit column - date of last update.'
/
PROMPT Creating Table 'DOCTOR'
CREATE TABLE DOCTOR
(DOCTOR_ID NUMBER(8,0)
,DOCTOR_FN VARCHAR2(25)
,DOCTOR_LN VARCHAR2(25)
,DOCTOR_PHONE VARCHAR2(15)
,DOCTOR_SSN VARCHAR2(11)
,CREATED_BY VARCHAR2(30)
,CREATED_DATE DATE
,MODIFIED_BY VARCHAR2(30)
,MODIFIED_DATE DATE
)
/
COMMENT ON TABLE DOCTOR IS 'Profile information for a doctor.'
/
COMMENT ON COLUMN DOCTOR.DOCTOR_ID IS 'The unique ID for a doctor.'
/
COMMENT ON COLUMN DOCTOR.DOCTOR_FN IS 'This doctor''s first name.'
/
COMMENT ON COLUMN DOCTOR.DOCTOR_LN IS 'The doctor''s last name.'
/
COMMENT ON COLUMN DOCTOR.DOCTOR_PHONE IS 'The doctor''s phone number.'
/
COMMENT ON COLUMN DOCTOR.DOCTOR_SSN IS 'The doctor''s social security number.'
/
COMMENT ON COLUMN DOCTOR.CREATED_BY IS 'Audit column - indicates user who inserted
data.'
/
COMMENT ON COLUMN DOCTOR.CREATED_DATE IS 'Audit column - indicates date of insert.'
/
COMMENT ON COLUMN DOCTOR.MODIFIED_BY IS 'Audit column - indicates who made last
update.'
/
COMMENT ON COLUMN DOCTOR.MODIFIED_DATE IS 'Audit column - date of last update.'
/
PROMPT Creating Table 'PATIENT'
CREATE TABLE PATIENT
(PATIENT_ID NUMBER(8,0)
,PATIENT_FN VARCHAR2(25)
,PATIENT_LN VARCHAR2(25)
,PHONE VARCHAR2(15)
,NOTES VARCHAR2(2000)
,DOCTOR_ID NUMBER(8,0)
,NURSE_ID NUMBER(8,0)
,CREATED_BY VARCHAR2(30)
,CREATED_DATE DATE
,MODIFIED_BY VARCHAR2(30)
,MODIFIED_DATE DATE
)
/
COMMENT ON TABLE PATIENT IS 'Profile information for a patient.'
/
COMMENT ON COLUMN PATIENT.PATIENT_ID IS 'The unique ID for a patient.'
/
COMMENT ON COLUMN PATIENT.PATIENT_FN IS 'This patient''s first name.'
/
COMMENT ON COLUMN PATIENT.PATIENT_LN IS 'The patient''s last name.'
/
COMMENT ON COLUMN PATIENT.PHONE IS 'The patient''s phone number.'
/
COMMENT ON COLUMN PATIENT.DOCTOR_ID IS 'The unique ID for a doctor.'
/
COMMENT ON COLUMN PATIENT.NURSE_ID IS 'The unique ID for a nurse.'
/
COMMENT ON COLUMN PATIENT.CREATED_BY IS 'Audit column - indicates user who inserted
data.'
/
COMMENT ON COLUMN PATIENT.CREATED_DATE IS 'Audit column - indicates date of insert.'
/
COMMENT ON COLUMN PATIENT.MODIFIED_BY IS 'Audit column - indicates who made last
update.'
/
COMMENT ON COLUMN PATIENT.MODIFIED_DATE IS 'Audit column - date of last update.'
/
PROMPT Creating Table 'PRESCRIPTION'
CREATE TABLE PRESCRIPTION
(PRESCRIPTION_ID NUMBER(8,0)
,DOCTOR_ID NUMBER(8,0)
,PATIENT_ID NUMBER(8,0)
,PRESCRIPTION_CHECK CHAR(1)
,PRESCRIPTION_NOTE VARCHAR2(2000)
,PRESCRIPTION_DATE DATE
,CREATED_BY VARCHAR2(30)
,CREATED_DATE DATE
,MODIFIED_BY VARCHAR2(30)
,MODIFIED_DATE DATE
)
/
COMMENT ON TABLE PRESCRIPTION IS 'Prescription information for a patient.'
/
COMMENT ON COLUMN PRESCRIPTION.PRESCRIPTION_ID IS 'The unique ID for a prescription.'
/
COMMENT ON COLUMN PRESCRIPTION.DOCTOR_ID IS 'The unique ID for a doctor'
/
COMMENT ON COLUMN PRESCRIPTION.PATIENT_ID IS 'The unique ID of a patient'
/
COMMENT ON COLUMN PRESCRIPTION.PRESCRIPTION_CHECK IS 'Used to check if
prescriptions are available'
/
COMMENT ON COLUMN PRESCRIPTION.PRESCRIPTION_DATE IS 'The date the prescription is to
be received'
/
COMMENT ON COLUMN PRESCRIPTION.CREATED_BY IS 'Audit column - indicates user who
inserted data.'
/
COMMENT ON COLUMN PRESCRIPTION.CREATED_DATE IS 'Audit column - indicates date of
insert.'
/
COMMENT ON COLUMN PRESCRIPTION.MODIFIED_BY IS 'Audit column - indicates who made
last update.'
/
COMMENT ON COLUMN PRESCRIPTION.MODIFIED_DATE IS 'Audit column - date of last
update.'
/
PROMPT Creating Table 'ASSIGNMENT'
CREATE TABLE ASSIGNMENT
(ASSIGNMENT_ID NUMBER(8,0)
,NURSE_ID NUMBER(8,0)
,DOCTOR_ID NUMBER(8,0)
,ASSIGNMENT_DATE DATE
,ASSIGNMENT_CAP CHAR(1)
,CREATED_BY VARCHAR2(30)
,CREATED_DATE DATE
,MODIFIED_BY VARCHAR2(30)
,MODIFIED_DATE DATE
)
/
COMMENT ON TABLE ASSIGNMENT IS 'Used to assign nurses to doctors'
/
COMMENT ON COLUMN ASSIGNMENT.ASSIGNMENT_ID IS 'The unique ID for an assignmet.'
/
COMMENT ON COLUMN ASSIGNMENT.NURSE_ID IS 'This unique ID for a nurse.'
/
COMMENT ON COLUMN ASSIGNMENT.DOCTOR_ID IS 'The unique ID for a doctor'
/
COMMENT ON COLUMN ASSIGNMENT.ASSIGNMENT_DATE IS 'The date of an assignment'
/
COMMENT ON COLUMN ASSIGNMENT.ASSIGNMENT_CAP IS 'Used to check if an assignment is
full F or incomplete I'
/
COMMENT ON COLUMN ASSIGNMENT.CREATED_BY IS 'Audit column - indicates user who
inserted data.'
/
COMMENT ON COLUMN ASSIGNMENT.CREATED_DATE IS 'Audit column - indicates date of
insert.'
/
COMMENT ON COLUMN ASSIGNMENT.MODIFIED_BY IS 'Audit column - indicates who made
last update.'
/
COMMENT ON COLUMN ASSIGNMENT.MODIFIED_DATE IS 'Audit column - date of last update.'
/
-- PROMPT healthsystem.ind
PROMPT Creating Unique Index 'NUR_NUR_SSN'
CREATE UNIQUE INDEX NUR_NURSE_SSN_UX ON NURSE (NURSE_SSN)
/
PROMPT Creating Unique Index 'DOC_DOC_SSN'
CREATE UNIQUE INDEX DOC_DOC_SSN_UX ON DOCTOR (DOCTOR_SSN)
/
PROMPT Creating Index 'PRE_PAT_FK_I'
CREATE INDEX PRE_PAT_FK_I ON PRESCRIPTION (PATIENT_ID)
/
PROMPT Creating Index 'PRE_DOC_FK_I'
CREATE INDEX PRE_DOC_FK_I ON PRESCRIPTION (DOCTOR_ID)
/
PROMPT Creating Index 'PAT_DOC_FK_I'
CREATE INDEX PAT_DOC_FK_I ON PATIENT (DOCTOR_ID)
/
PROMPT Creating Index 'ASS_DOC_FK_I'
CREATE INDEX ASS_DOC_FK_I ON ASSIGNMENT (DOCTOR_ID)
/
PROMPT Creating Index 'ASS_NUR_FK_I'
CREATE INDEX ASS_NUR_FK_I ON ASSIGNMENT (NURSE_ID)
/
PROMPT Creating Index 'PAT_NUR_FK_I'
CREATE INDEX PAT_NUR_FK_I ON PATIENT (NURSE_ID)
/
PROMPT Creating Index 'PAT_PATIENT_LN_IDX'
CREATE INDEX PAT_PATIENT_LN_IDX ON PATIENT (PATIENT_LN)
/
PROMPT Creating Index 'NUR_NURSE_LN_IDX'
CREATE INDEX NUR_NURSE_LN_IDX ON NURSE (NURSE_LN)
/
PROMPT Creating Index 'DOC_DOCTOR_LN_IDX'
CREATE INDEX DOCTOR_DOCTOR_LN_IDX ON DOCTOR (DOCTOR_LN)
/
-- PROMPT healthsystem.con
PROMPT Creating Check Constraints on 'PATIENT'
ALTER TABLE PATIENT
MODIFY(PATIENT_ID CONSTRAINT PAT_PATIENT_ID_NNULL NOT NULL)
MODIFY(DOCTOR_ID CONSTRAINT PAT_DOCTOR_ID_NNULL NOT NULL)
MODIFY(NURSE_ID CONSTRAINT PAT_NURSE_ID_NNULL NOT NULL)
MODIFY(MODIFIED_BY CONSTRAINT PAT_MODIFIED_BY_NNULL NOT NULL)
MODIFY(CREATED_BY CONSTRAINT PAT_CREATED_BY_NNULL NOT NULL)
MODIFY(MODIFIED_DATE CONSTRAINT PAT_MODIFIED_DATE_NNULL NOT NULL)
MODIFY(CREATED_DATE CONSTRAINT PAT_CREATED_DATE_NNULL NOT NULL)
/
PROMPT Creating Check Constraints on 'PRESCRIPTION'
ALTER TABLE PRESCRIPTION
MODIFY(PRESCRIPTION_ID CONSTRAINT PRE_PRESCRIPTION_ID_NNULL NOT NULL)
MODIFY(PATIENT_ID CONSTRAINT PRE_PATIENT_ID_NNULL NOT NULL)
MODIFY(DOCTOR_ID CONSTRAINT PRE_DOCTOR_ID_NNULL NOT NULL)
MODIFY(PRESCRIPTION_CHECK CONSTRAINT PRE_PRESCRIPTION_CHECK_NNULL NOT
NULL)
MODIFY(MODIFIED_BY CONSTRAINT PRE_MODIFIED_BY_NNULL NOT NULL)
MODIFY(CREATED_BY CONSTRAINT PRE_CREATED_BY_NNULL NOT NULL)
MODIFY(MODIFIED_DATE CONSTRAINT PRE_MODIFIED_DATE_NNULL NOT NULL)
MODIFY(CREATED_DATE CONSTRAINT PRE_CREATED_DATE_NNULL NOT NULL)
ADD CONSTRAINT PRE_PRESCRIPTION_CHECK_LENGTH CHECK
(LENGTH(prescription_check)=1)
/
PROMPT Creating Check Constraints on 'DOCTOR'
ALTER TABLE DOCTOR
MODIFY(DOCTOR_ID CONSTRAINT DOC_DOCTOR_ID_NNULL NOT NULL)
MODIFY(DOCTOR_LN CONSTRAINT DOC_DOCTOR_LN_NNULL NOT NULL)
MODIFY(MODIFIED_BY CONSTRAINT DOC_MODIFIED_BY_NNULL NOT NULL)
MODIFY(CREATED_BY CONSTRAINT DOC_CREATED_BY_NNULL NOT NULL)
MODIFY(MODIFIED_DATE CONSTRAINT DOC_MODIFIED_DATE_NNULL NOT NULL)
MODIFY(CREATED_DATE CONSTRAINT DOC_CREATED_DATE_NNULL NOT NULL)
/
PROMPT Creating Check Constraints on 'ASSIGNMENT'
ALTER TABLE ASSIGNMENT
MODIFY(ASSIGNMENT_ID CONSTRAINT ASS_ASSIGNMENT_ID_NNULL NOT NULL)
MODIFY(DOCTOR_ID CONSTRAINT ASS_DOCTOR_ID_NNULL NOT NULL)
MODIFY(NURSE_ID CONSTRAINT ASS_NURSE_ID_NNULL NOT NULL)
MODIFY(ASSIGNMENT_CAP CONSTRAINT ASS_ASSIGNMENT_CAP_NNULL NOT NULL)
MODIFY(MODIFIED_BY CONSTRAINT ASS_MODIFIED_BY_NNULL NOT NULL)
MODIFY(CREATED_BY CONSTRAINT ASS_CREATED_BY_NNULL NOT NULL)
MODIFY(MODIFIED_DATE CONSTRAINT ASS_MODIFIED_DATE_NNULL NOT NULL)
MODIFY(CREATED_DATE CONSTRAINT ASS_CREATED_DATE_NNULL NOT NULL)
ADD CONSTRAINT ASS_ASSIGNMENT_CAP_LENGTH CHECK (LENGTH(assignment_cap)=1)
/
PROMPT Creating Check Constraints on 'NURSE'
ALTER TABLE NURSE
MODIFY(NURSE_ID CONSTRAINT NUR_NURSE_ID_NNULL NOT NULL)
MODIFY(NURSE_LN CONSTRAINT NUR_NURSE_LN_NNULL NOT NULL)
MODIFY(MODIFIED_BY CONSTRAINT NUR_MODIFIED_BY_NNULL NOT NULL)
MODIFY(CREATED_BY CONSTRAINT NUR_CREATED_BY_NNULL NOT NULL)
MODIFY(MODIFIED_DATE CONSTRAINT NUR_MODIFIED_DATE_NNULL NOT NULL)
MODIFY(CREATED_DATE CONSTRAINT NUR_CREATED_DATE_NNULL NOT NULL)
/
PROMPT Creating Primary Key on 'PATIENT'
ALTER TABLE PATIENT
ADD CONSTRAINT PAT_PK PRIMARY KEY (PATIENT_ID)
/
PROMPT Creating Primary Key on 'PRESCRIPTION'
ALTER TABLE PRESCRIPTION
ADD CONSTRAINT PRE_PK PRIMARY KEY (PRESCRIPTION_ID)
/
PROMPT Creating Primary Key on 'DOCTOR'
ALTER TABLE DOCTOR
ADD CONSTRAINT DOC_PK PRIMARY KEY (DOCTOR_ID)
/
PROMPT Creating Primary Key on 'NURSE'
ALTER TABLE NURSE
ADD CONSTRAINT NUR_PK PRIMARY KEY (NURSE_ID)
/
PROMPT Creating Primary Key on 'ASSIGNMENT'
ALTER TABLE ASSIGNMENT
ADD CONSTRAINT ASS_PK PRIMARY KEY (ASSIGNMENT_ID, NURSE_ID, DOCTOR_ID)
/
PROMPT Creating Foreign Keys on 'PATIENT'
ALTER TABLE PATIENT ADD CONSTRAINT
PAT_DOC_FK FOREIGN KEY
(DOCTOR_ID) REFERENCES DOCTOR
(DOCTOR_ID) ADD CONSTRAINT
PAT_NUR_FK FOREIGN KEY
(NURSE_ID) REFERENCES NURSE
(NURSE_ID)
/
PROMPT Creating Foreign Keys on 'PRESCRIPTION'
ALTER TABLE PRESCRIPTION ADD CONSTRAINT
PRE_PAT_FK FOREIGN KEY
(PATIENT_ID) REFERENCES PATIENT
(PATIENT_ID) ADD CONSTRAINT
PRE_DOC_FK FOREIGN KEY
(DOCTOR_ID) REFERENCES DOCTOR
(DOCTOR_ID)
/
PROMPT Creating Foreign Keys on 'ASSIGNMENT'
ALTER TABLE ASSIGNMENT ADD CONSTRAINT
ASS_DOC_FK FOREIGN KEY
(DOCTOR_ID) REFERENCES DOCTOR
(DOCTOR_ID) ADD CONSTRAINT
ASS_NUR_FK FOREIGN KEY
(NURSE_ID) REFERENCES NURSE
(NURSE_ID)
/
-- PROMPT healthsystem.sqs
PROMPT Creating Sequence 'PATIENT_ID_SEQ'
CREATE SEQUENCE PATIENT_ID_SEQ
INCREMENT BY 1
START WITH 300
NOMAXVALUE
MINVALUE 1
NOCYCLE
NOCACHE
/
PROMPT Creating Sequence 'DOCTOR_ID_SEQ'
CREATE SEQUENCE DOCTOR_ID_SEQ
INCREMENT BY 1
START WITH 500
NOMAXVALUE
MINVALUE 1
NOCYCLE
NOCACHE
/
PROMPT Creating Sequence 'NURSE_ID_SEQ'
CREATE SEQUENCE NURSE_ID_SEQ
INCREMENT BY 1
START WITH 600
NOMAXVALUE
MINVALUE 1
NOCYCLE
NOCACHE
/
PROMPT Creating Sequence 'PRESCRIPTION_ID_SEQ'
CREATE SEQUENCE PRESCRIPTION_ID_SEQ
INCREMENT BY 1
START WITH 100
NOMAXVALUE
MINVALUE 1
NOCYCLE
NOCACHE
/
PROMPT Creating Sequence 'ASSIGNMENT_ID_SEQ'
CREATE SEQUENCE ASSIGNMENT_ID_SEQ
INCREMENT BY 1
START WITH 222
NOMAXVALUE
MINVALUE 1
NOCYCLE
NOCACHE
/
-- PROMPT healthsystem.vw
PROMPT Creating View 'VW_PAT'
CREATE OR REPLACE VIEW VW_PAT AS
SELECT PATIENT_ID, PATIENT_FN, PATIENT_LN, PHONE, NOTES, DOCTOR_ID, NURSE_ID
FROM PATIENT
/
PROMPT Creating View 'VW_DOC'
CREATE OR REPLACE VIEW VW_DOC AS
SELECT DOCTOR_ID, DOCTOR_FN, DOCTOR_LN, DOCTOR_PHONE, DOCTOR_SSN FROM
DOCTOR
/
PROMPT Creating View 'VW_NUR'
CREATE OR REPLACE VIEW VW_NUR AS
SELECT NURSE_ID, NURSE_FN, NURSE_LN, NURSE_PHONE, NURSE_SSN FROM NURSE
/
PROMPT Creating View 'VW_PRE'
CREATE OR REPLACE VIEW VW_PRE AS
SELECT PRESCRIPTION_ID, DOCTOR_ID, PATIENT_ID, PRESCRIPTION_CHECK,
PRESCRIPTION_NOTE PRESCRIPTION_DATE FROM PRESCRIPTION
/
PROMPT Creating View 'VW_ASS'
CREATE OR REPLACE VIEW VW_ASS AS
SELECT ASSIGNMENT_ID, NURSE_ID, DOCTOR_ID, ASSIGNMENT_DATE,
ASSIGNMENT_CAP FROM ASSIGNMENT
/
-- PROMPT healthsystem.tri
PROMPT Creating Trigger 'BIUR_PAT_TRG'
CREATE OR REPLACE TRIGGER BIUR_PAT_TRG
BEFORE INSERT OR UPDATE ON PATIENT
FOR EACH ROW
BEGIN
IF :NEW.patient_id IS NULL THEN
:NEW.patient_id :=PATIENT_ID_SEQ.NEXTVAL;
END IF;
IF INSERTING THEN
IF :NEW.created_by IS NULL THEN :NEW.created_by := USER; END IF;
IF :NEW.created_date IS NULL THEN :NEW.created_date :=SYSDATE; END IF;
END IF;
IF INSERTING OR UPDATING THEN
IF :NEW.modified_by IS NULL THEN :NEW.modified_by := USER; END IF;
IF :NEW.modified_date IS NULL THEN :NEW.modified_date := SYSDATE; END IF;
END IF;
END;
/
PROMPT Creating Trigger 'BIUR_DOC_TRG'
CREATE OR REPLACE TRIGGER BIUR_DOC_TRG
BEFORE INSERT OR UPDATE ON DOCTOR
FOR EACH ROW
BEGIN
IF :NEW.doctor_id IS NULL THEN
:NEW.doctor_id := DOCTOR_ID_SEQ.NEXTVAL;
END IF;
IF INSERTING THEN
IF :NEW.created_by IS NULL THEN :NEW.created_by := USER; END IF;
IF :NEW.created_date IS NULL THEN :NEW.created_date :=SYSDATE; END IF;
END IF;
IF INSERTING OR UPDATING THEN
IF :NEW.modified_by IS NULL THEN :NEW.modified_by := USER; END IF;
IF :NEW.modified_date IS NULL THEN :NEW.modified_date := SYSDATE; END IF;
END IF;
END;
/
PROMPT Creating Trigger 'BIUR_NUR_TRG'
CREATE OR REPLACE TRIGGER BIUR_NUR_TRG
BEFORE INSERT OR UPDATE ON NURSE
FOR EACH ROW
BEGIN
IF :NEW.nurse_id IS NULL THEN
:NEW.nurse_id := NURSE_ID_SEQ.NEXTVAL;
END IF;
IF INSERTING THEN
IF :NEW.created_by IS NULL THEN :NEW.created_by := USER; END IF;
IF :NEW.created_date IS NULL THEN :NEW.created_date :=SYSDATE; END IF;
END IF;
IF INSERTING OR UPDATING THEN
IF :NEW.modified_by IS NULL THEN :NEW.modified_by := USER; END IF;
IF :NEW.modified_date IS NULL THEN :NEW.modified_date := SYSDATE; END IF;
END IF;
END;
/
PROMPT Creating Trigger 'BIUR_PRE_TRG'
CREATE OR REPLACE TRIGGER BIUR_PRE_TRG
BEFORE INSERT OR UPDATE ON PRESCRIPTION
FOR EACH ROW
BEGIN
IF :NEW.prescription_id IS NULL THEN
:NEW.prescription_id :=PRESCRIPTION_ID_SEQ.NEXTVAL;
END IF;
IF INSERTING THEN
IF :NEW.created_by IS NULL THEN :NEW.created_by := USER; END IF;
IF :NEW.created_date IS NULL THEN :NEW.created_date :=SYSDATE; END IF;
IF :NEW.prescription_date IS NULL THEN :NEW.prescription_date :=SYSDATE; END IF;
END IF;
IF INSERTING OR UPDATING THEN
IF :NEW.modified_by IS NULL THEN :NEW.modified_by := USER; END IF;
IF :NEW.modified_date IS NULL THEN :NEW.modified_date := SYSDATE; END IF;
END IF;
END;
/
PROMPT Creating Trigger 'BIUR_ASS_TRG'
CREATE OR REPLACE TRIGGER BIUR_ASS_TRG
BEFORE INSERT OR UPDATE ON ASSIGNMENT
FOR EACH ROW
BEGIN
IF :NEW.assignment_id IS NULL THEN
:NEW.assignment_id :=ASSIGNMENT_ID_SEQ.NEXTVAL;
END IF;
IF INSERTING THEN
IF :NEW.created_by IS NULL THEN :NEW.created_by := USER; END IF;
IF :NEW.created_date IS NULL THEN :NEW.created_date :=SYSDATE; END IF;
IF :NEW.assignment_date IS NULL THEN :NEW.assignment_date :=SYSDATE; END IF;
END IF;
IF INSERTING OR UPDATING THEN
IF :NEW.modified_by IS NULL THEN :NEW.modified_by := USER; END IF;
IF :NEW.modified_date IS NULL THEN :NEW.modified_date := SYSDATE; END IF;
END IF;
END;
/
SET ECHO OFF
PROMPT ** ****************************************************** **
PROMPT ** Checking the DBMS data dictionary to verify successful **
PROMPT ** creationg of database objects. **
PROMPT ** ****************************************************** **
SET ECHO OFF
SET PAGES 0
DML (Data Manipulation Language)
-- PROMPT insertNUR.sql
INSERT INTO Nurse (Nurse_FN, Nurse_LN, Nurse_Phone, Nurse_SSN) VALUES ('Obehi','Ukpebor',
'2403159874', '223-45-9005');
INSERT INTO Nurse (Nurse_FN, Nurse_LN, Nurse_Phone, Nurse_SSN) VALUES ('Bukky','Saula',
'3015469874', '301-59-0015');
INSERT INTO Nurse (Nurse_FN, Nurse_LN, Nurse_Phone, Nurse_SSN) VALUES ('Abdul','Olawin',
'3019874569', '987-99-3465');
INSERT INTO Nurse (Nurse_FN, Nurse_LN, Nurse_Phone, Nurse_SSN) VALUES ('Adaeze','Gold',
'7574189625', '205-70-9685');
INSERT INTO Nurse (Nurse_FN, Nurse_LN, Nurse_Phone, Nurse_SSN) VALUES ('Sharon','Heather',
'2406941268', '789-67-7012');
INSERT INTO Nurse (Nurse_FN, Nurse_LN, Nurse_Phone, Nurse_SSN) VALUES ('Cyndy','Watsons',
'7574181258', '801-34-9745');
INSERT INTO Nurse (Nurse_FN, Nurse_LN, Nurse_Phone, Nurse_SSN) VALUES ('Mercy','Johnson',
'2406940937', '888-16-9863');
INSERT INTO Nurse (Nurse_FN, Nurse_LN, Nurse_Phone, Nurse_SSN) VALUES ('Josephine','Sawyer',
'3017891268', '705-62-3698');
INSERT INTO Nurse (Nurse_FN, Nurse_LN, Nurse_Phone, Nurse_SSN) VALUES ('Victoria','Abigail',
'3015691268', '968-99-2894');
INSERT INTO Nurse (Nurse_FN, Nurse_LN, Nurse_Phone, Nurse_SSN) VALUES ('Sarah','Watsons',
'7576941268', '756-73-4856');
COMMIT;
-- PROMPT insertDOC.sql
INSERT INTO Doctor (Doctor_FN, Doctor_LN, Doctor_Phone, Doctor_SSN) VALUES ('Adam','Sandler',
'2403159874', '201-45-9875');
INSERT INTO Doctor (Doctor_FN, Doctor_LN, Doctor_Phone, Doctor_SSN) VALUES ('Mark','Wahlberg',
'3012545698', '325-98-1256');
INSERT INTO Doctor (Doctor_FN, Doctor_LN, Doctor_Phone, Doctor_SSN) VALUES ('Dwayne','Johnson',
'2405146987', '888-45-9862');
INSERT INTO Doctor (Doctor_FN, Doctor_LN, Doctor_Phone, Doctor_SSN) VALUES ('Kevin','Hart',
'2404658978', '251-98-7894');
INSERT INTO Doctor (Doctor_FN, Doctor_LN, Doctor_Phone, Doctor_SSN) VALUES ('James','Bond',
'2409685789', '240-12-0590');
INSERT INTO Doctor (Doctor_FN, Doctor_LN, Doctor_Phone, Doctor_SSN) VALUES ('Harry','Potter',
'3012546987', '322-98-9775');
INSERT INTO Doctor (Doctor_FN, Doctor_LN, Doctor_Phone, Doctor_SSN) VALUES ('Michael','Owens',
'3012147895', '298-68-0205');
INSERT INTO Doctor (Doctor_FN, Doctor_LN, Doctor_Phone, Doctor_SSN) VALUES ('Jennifer','Lopez',
'2403198745', '301-40-9700');
INSERT INTO Doctor (Doctor_FN, Doctor_LN, Doctor_Phone, Doctor_SSN) VALUES ('Mary','Dillehad',
'7576984563', '800-36-9862');
INSERT INTO Doctor (Doctor_FN, Doctor_LN, Doctor_Phone, Doctor_SSN) VALUES ('Elizabeth','Swan',
'3012547896', '701-36-9865');
COMMIT;
-- PROMPT insertPAT.sql
INSERT INTO Patient (Patient_FN, Patient_LN, Phone, Notes, Doctor_ID, Nurse_ID) VALUES ('John-
Bosco','Cotley', '3012569874', 'Elevated blood pressure. Symptoms getting worst.', 503, 603);
INSERT INTO Patient (Patient_FN, Patient_LN, Phone, Notes, Doctor_ID, Nurse_ID) VALUES
('Sandra','Opone', '3406985452', 'Recovering. Needs more supervision.', 506, 606);
INSERT INTO Patient (Patient_FN, Patient_LN, Phone, Notes, Doctor_ID, Nurse_ID) VALUES
('Miley','Cyrus', '3012563214', 'Neck pain. Stomach upset.', 503, 601);
INSERT INTO Patient (Patient_FN, Patient_LN, Phone, Notes, Doctor_ID, Nurse_ID) VALUES ('Joshua','Ali',
'2409856321', 'Responding well to treatment. Minmal supervision required.', 506, 607);
INSERT INTO Patient (Patient_FN, Patient_LN, Phone, Notes, Doctor_ID, Nurse_ID) VALUES
('Bobo','Usen', '2026563652', 'Reacts to chloroquine and peptol.', 507, 602);
INSERT INTO Patient (Patient_FN, Patient_LN, Phone, Notes, Doctor_ID, Nurse_ID) VALUES
('Hannah','Montana', '3015262463', 'High blood pressure, lower leg pain.', 509, 608);
INSERT INTO Patient (Patient_FN, Patient_LN, Phone, Notes, Doctor_ID, Nurse_ID) VALUES
('Elliot','Carmelo', '7579860937', 'More supervision needed. Not reacting to medication.', 508, 604);
INSERT INTO Patient (Patient_FN, Patient_LN, Phone, Notes, Doctor_ID, Nurse_ID) VALUES
('Matthew','Wilson', '3016987412', 'Stomach upset and constipation.', 502, 605);
INSERT INTO Patient (Patient_FN, Patient_LN, Phone, Notes, Doctor_ID, Nurse_ID) VALUES
('Sugar','Wilslow', '2403012569', 'Toe fracture.', 502, 608);
INSERT INTO Patient (Patient_FN, Patient_LN, Phone, Notes, Doctor_ID, Nurse_ID) VALUES
('Fahrdad','Gushavi', '8886981268', 'Knee dislocated. Non-stop bleeding', 509, 609);
COMMIT;
-- PROMPT insertPRE.sql
INSERT INTO Prescription (Doctor_ID, Patient_ID, Prescription_Check, Prescription_Note) VALUES (506,
302, 'Y', 'Bystolic-Oxycontin');
INSERT INTO Prescription (Doctor_ID, Patient_ID, Prescription_Check, Prescription_Note) VALUES (506,
301, 'N', 'Bystolic-Nexium-Advil');
INSERT INTO Prescription (Doctor_ID, Patient_ID, Prescription_Check, Prescription_Note) VALUES (506,
303, 'Y', 'Tylenol-Bystolic-Tylenol');
INSERT INTO Prescription (Doctor_ID, Patient_ID, Prescription_Check, Prescription_Note) VALUES (502,
308, 'Y', 'Advil-Pepsid');
INSERT INTO Prescription (Doctor_ID, Patient_ID, Prescription_Check, Prescription_Note) VALUES (500,
300, 'N', 'Celebrex-Oxycontin-Amoxil');
INSERT INTO Prescription (Doctor_ID, Patient_ID, Prescription_Check, Prescription_Note) VALUES (501,
309, 'Y', 'Nasonex-Panadol');
INSERT INTO Prescription (Doctor_ID, Patient_ID, Prescription_Check, Prescription_Note) VALUES (501,
306, 'N', 'Flovent-Oxycontin');
INSERT INTO Prescription (Doctor_ID, Patient_ID, Prescription_Check, Prescription_Note) VALUES (507,
307, 'N', 'Amoxil-Bystolic-Pepsid');
INSERT INTO Prescription (Doctor_ID, Patient_ID, Prescription_Check, Prescription_Note) VALUES (507,
305, 'Y', 'Piriton-Novagen');
INSERT INTO Prescription (Doctor_ID, Patient_ID, Prescription_Check, Prescription_Note) VALUES (507,
304, 'Y', 'Advil');
COMMIT;
-- PROMPT insertASS.sql
INSERT INTO Assignment (Nurse_ID, Doctor_ID, Assignment_Cap) VALUES (602, 504, '1');
INSERT INTO Assignment (Nurse_ID, Doctor_ID, Assignment_Cap) VALUES (602, 502, '2');
INSERT INTO Assignment (Nurse_ID, Doctor_ID, Assignment_Cap) VALUES (609, 500, '1');
INSERT INTO Assignment (Nurse_ID, Doctor_ID, Assignment_Cap) VALUES (607, 505, '3');
INSERT INTO Assignment (Nurse_ID, Doctor_ID, Assignment_Cap) VALUES (607, 506, '1');
INSERT INTO Assignment (Nurse_ID, Doctor_ID, Assignment_Cap) VALUES (601, 507, '4');
INSERT INTO Assignment (Nurse_ID, Doctor_ID, Assignment_Cap) VALUES (604, 507, '4');
INSERT INTO Assignment (Nurse_ID, Doctor_ID, Assignment_Cap) VALUES (605, 502, '2');
INSERT INTO Assignment (Nurse_ID, Doctor_ID, Assignment_Cap) VALUES (605, 505, '3');
INSERT INTO Assignment (Nurse_ID, Doctor_ID, Assignment_Cap) VALUES (603, 501, '1');
COMMIT;
DML (Data Manipulation Language)
/**--1. Select all columns and all rows from Patient.*/
SELECT * FROM Patient;
/**--2. Select 5 columns and all rows from one Doctor.*/
SELECT Doctor_FN, Doctor_LN, Doctor_Phone, Created_By, Modified_By From Doctor;
/**--3. Select all columns and all rows from VW_NUR.*/
SELECT * FROM VW_NUR;
/**--4. Using a join on 2 tables, select all columns and all rows from the tables without the use of
a Cartesian product. */
SELECT * FROM Nurse
INNER JOIN Patient ON Nurse.Nurse_ID = Patient.Nurse_ID;
/**--5. Select and order data retrieved from one Prescription.*/
SELECT * FROM Prescription
ORDER BY Doctor_ID ASC;
/**--6. Using a join on 3 tables, select 5 columns from the 3 tables. Use syntax that would limit
the output to 10 rows. */
SELECT Patient.Patient_FN, Patient.Patient_LN, Patient.Notes, Nurse.Nurse_LN,
Doctor.Doctor_LN
FROM Patient
INNER JOIN Doctor ON Doctor.Doctor_ID = Patient.Doctor_ID
INNER JOIN Nurse ON Nurse.Nurse_ID = Patient.Nurse_ID;
/**--7. Select distinct rows using joins on 3 tables. */
SELECT DISTINCT Patient.Patient_FN, Patient.Patient_LN, Prescription.Prescription_Note,
Doctor.Doctor_LN
FROM Prescription
INNER JOIN Doctor ON Doctor.Doctor_ID = Prescription.Doctor_ID
INNER JOIN Patient ON Patient.Patient_ID = Prescription.Patient_ID;
/**--8. Use GROUP BY & HAVING in a select statement using one or more tables.*/
SELECT DISTINCT Patient.Patient_FN, Patient.Patient_LN, Doctor.Doctor_LN,
Patient.Doctor_ID, Count(Patient.Doctor_ID) AS DoctorCount
FROM Patient
INNER JOIN Doctor ON Doctor.Doctor_ID = Patient.Doctor_ID
GROUP BY Patient.Patient_FN, Patient.Patient_LN, Doctor.Doctor_LN, Patient.Doctor_ID
HAVING COUNT(Patient.Doctor_ID) = 1;
/**--9. Use IN clause to select data from one or more tables.*/
SELECT Patient.Patient_FN, Patient.Patient_LN, Doctor.Doctor_LN FROM Patient
INNER JOIN Doctor ON Patient.Doctor_ID = Doctor.Doctor_ID
WHERE Doctor.Doctor_ID IN
(SELECT Doctor.Doctor_ID FROM Doctor WHERE Doctor.Doctor_LN = 'Lopez');
/**--10. Select length of one column from one table (use LENGTH function).*/
SELECT Prescription_ID, Prescription_Check, LENGTH(Prescription_Note) AS PrescLength
From Prescription;
/**--11. Use the SQL DELETE statement to delete one record from one table. Add select
statements to demonstrate the table contents before and after the DELETE statement. Make sure
to use ROLLBACK afterwards so that the data will not be physically removed.*/
SELECT * FROM Prescription;
DELETE FROM Prescription WHERE Prescription_Note = 'Advil';
SELECT * FROM Prescription;
ROLLBACK;
SELECT * FROM Prescription;
/**--12. Use the SQL UPDATE statement to change some data. Add select statements to
demonstrate the table contents before and after the UPDATE statement. You can either
COMMIT or ROLLBACK afterwards.*/
SELECT * FROM Patient;
UPDATE Patient
SET Notes = 'Toe dislocation'
WHERE Patient_LN = 'Wilslow';
SELECT * FROM Patient;
ROLLBACK;
/**--13. Display the doctor's and patient's last name, along with the patient notes (Doctor_LN,
Patient_LN, Notes)*/
SELECT Doctor.Doctor_LN, Patient.Patient_LN, Patient.Notes FROM Prescription
INNER JOIN Doctor ON Prescription.Doctor_ID = Doctor.Doctor_ID
INNER JOIN Patient ON Prescription.Patient_ID = Patient.Patient_ID
WHERE Prescription.Patient_ID IN
(SELECT Patient.Patient_ID FROM Patient WHERE Patient.Patient_LN = 'Opone');
/**--14. Display the Nurse's last name and assignment cap along with its count*/
SELECT Nurse.Nurse_LN, Assignment.Assignment_Cap, Count(Assignment.Doctor_ID) AS
Doctor_Cap
FROM Assignment
INNER JOIN Nurse ON Nurse.Nurse_ID = Assignment.Nurse_ID
GROUP BY Nurse.Nurse_LN, Assignment.Assignment_Cap;
/**--15. Display the nurses (last name only) who have an assignment capacity of 4*/
SELECT Nurse.Nurse_LN, Assignment.Assignment_Cap
FROM Nurse
INNER JOIN Assignment ON Nurse.Nurse_ID = Assignment.Nurse_ID
WHERE Assignment.Doctor_ID = 507;
/**--16. Show the Date a prescription was checked along with the patients name*/
SELECT Prescription.Prescription_Date, Patient.Patient_FN, Patient.Patient_LN FROM Patient
INNER JOIN Prescription ON Patient.Patient_ID = Prescription.Patient_ID
WHERE Patient.Patient_LN = 'Usen';
/**--17. Show the doctors and nurses who took care of Bobo Usen */
SELECT Nurse.Nurse_FN, Nurse.Nurse_LN, Patient.Patient_FN, Patient.Patient_LN,
Doctor.Doctor_FN, Doctor.Doctor_LN FROM Patient
INNER JOIN Doctor ON Patient.Doctor_ID = Doctor.Doctor_ID
INNER JOIN Nurse ON Patient.Nurse_ID = Nurse.Nurse_ID
WHERE Nurse.Nurse_ID IN
(SELECT Nurse.Nurse_ID FROM Nurse WHERE Nurse.Nurse_LN = 'Olawin');
/**--18. Assign a nurse to help doctors with less than two patients */
SELECT * FROM Assignment;
UPDATE Assignment
SET Assignment.Nurse_ID = 602
WHERE Assignment.Assignment_CAP < 2;
SELECT * FROM Assignment;
ROLLBACK;
SELECT * FROM Assignment;
/**--19. Find out all the patients who have all the prescription requirements fufulled*/
SELECT Patient.Patient_FN, Patient.Patient_LN, Prescription.Prescription_Check FROM
Patient
INNER JOIN Prescription ON Patient.Patient_ID = Prescription.Patient_ID
WHERE Prescription.Prescription_Check = 'Y';

More Related Content

Similar to KingsleyUsen_HospitalDatabase

Hospital database management_system_sql
Hospital database management_system_sqlHospital database management_system_sql
Hospital database management_system_sqlSumedhMasal
 
Hospital database management_system_sql
Hospital database management_system_sqlHospital database management_system_sql
Hospital database management_system_sqlSumedhMasal
 
Hosiptal-MS-PPT-zl64ci.pptx
Hosiptal-MS-PPT-zl64ci.pptxHosiptal-MS-PPT-zl64ci.pptx
Hosiptal-MS-PPT-zl64ci.pptxrohanthombre2
 
CIS336 Lab 2 The Expanded Entity Relationship DiagramLAB OVERVI.docx
CIS336 Lab 2 The Expanded Entity Relationship DiagramLAB OVERVI.docxCIS336 Lab 2 The Expanded Entity Relationship DiagramLAB OVERVI.docx
CIS336 Lab 2 The Expanded Entity Relationship DiagramLAB OVERVI.docxclarebernice
 
IS 6156 Jean Donnelly 90079094 Brendan McSweeney 114223513 Tim Walsh 102859661
IS 6156 Jean Donnelly 90079094 Brendan McSweeney 114223513 Tim Walsh 102859661IS 6156 Jean Donnelly 90079094 Brendan McSweeney 114223513 Tim Walsh 102859661
IS 6156 Jean Donnelly 90079094 Brendan McSweeney 114223513 Tim Walsh 102859661Brendan Mc Sweeney
 
Hospital mangement system report file
Hospital mangement system report fileHospital mangement system report file
Hospital mangement system report fileNausheen Hasan
 
Dbms mini project
Dbms mini projectDbms mini project
Dbms mini projectHome
 
Smart health disease prediction python django
Smart health disease prediction python djangoSmart health disease prediction python django
Smart health disease prediction python djangoShaikSalman28
 
Below is my program, I just have some issues when I want to check ou.pdf
Below is my program, I just have some issues when I want to check ou.pdfBelow is my program, I just have some issues when I want to check ou.pdf
Below is my program, I just have some issues when I want to check ou.pdfdhavalbl38
 
Presentation dental treatment & management application project
Presentation dental treatment & management application project Presentation dental treatment & management application project
Presentation dental treatment & management application project Zakirul Islam
 
Umldiagramforhospitalmanagementsystem 140425070951-phpapp02
Umldiagramforhospitalmanagementsystem 140425070951-phpapp02Umldiagramforhospitalmanagementsystem 140425070951-phpapp02
Umldiagramforhospitalmanagementsystem 140425070951-phpapp02Vivek Sharma
 
Uml diagram for_hospital_management_system
Uml diagram for_hospital_management_systemUml diagram for_hospital_management_system
Uml diagram for_hospital_management_systemPradeep Bhosale
 
Smart Health Disease Prediction django machinelearning.pptx
Smart Health Disease Prediction django machinelearning.pptxSmart Health Disease Prediction django machinelearning.pptx
Smart Health Disease Prediction django machinelearning.pptxsaiproject
 
Hospital Management System Presentation
Hospital Management System PresentationHospital Management System Presentation
Hospital Management System PresentationSanjeev Kumar Rao
 
Srs hospital management
Srs hospital managementSrs hospital management
Srs hospital managementmaamir farooq
 
HI300 Unit 6 Secondary Data Sources - DiscussionSecondary Dat.docx
HI300 Unit 6 Secondary Data Sources - DiscussionSecondary Dat.docxHI300 Unit 6 Secondary Data Sources - DiscussionSecondary Dat.docx
HI300 Unit 6 Secondary Data Sources - DiscussionSecondary Dat.docxAbramMartino96
 
In the given a database is used to.pdf
In the given a database is used to.pdfIn the given a database is used to.pdf
In the given a database is used to.pdfbkbk37
 
SRS for Hospital Management System
SRS for Hospital Management SystemSRS for Hospital Management System
SRS for Hospital Management Systemkataria Arvind
 

Similar to KingsleyUsen_HospitalDatabase (20)

Hospital database management_system_sql
Hospital database management_system_sqlHospital database management_system_sql
Hospital database management_system_sql
 
Hospital database management_system_sql
Hospital database management_system_sqlHospital database management_system_sql
Hospital database management_system_sql
 
Hosiptal-MS-PPT-zl64ci.pptx
Hosiptal-MS-PPT-zl64ci.pptxHosiptal-MS-PPT-zl64ci.pptx
Hosiptal-MS-PPT-zl64ci.pptx
 
CIS336 Lab 2 The Expanded Entity Relationship DiagramLAB OVERVI.docx
CIS336 Lab 2 The Expanded Entity Relationship DiagramLAB OVERVI.docxCIS336 Lab 2 The Expanded Entity Relationship DiagramLAB OVERVI.docx
CIS336 Lab 2 The Expanded Entity Relationship DiagramLAB OVERVI.docx
 
IS 6156 Jean Donnelly 90079094 Brendan McSweeney 114223513 Tim Walsh 102859661
IS 6156 Jean Donnelly 90079094 Brendan McSweeney 114223513 Tim Walsh 102859661IS 6156 Jean Donnelly 90079094 Brendan McSweeney 114223513 Tim Walsh 102859661
IS 6156 Jean Donnelly 90079094 Brendan McSweeney 114223513 Tim Walsh 102859661
 
Hospital mangement system report file
Hospital mangement system report fileHospital mangement system report file
Hospital mangement system report file
 
Dbms mini project
Dbms mini projectDbms mini project
Dbms mini project
 
Smart health disease prediction python django
Smart health disease prediction python djangoSmart health disease prediction python django
Smart health disease prediction python django
 
Below is my program, I just have some issues when I want to check ou.pdf
Below is my program, I just have some issues when I want to check ou.pdfBelow is my program, I just have some issues when I want to check ou.pdf
Below is my program, I just have some issues when I want to check ou.pdf
 
Presentation dental treatment & management application project
Presentation dental treatment & management application project Presentation dental treatment & management application project
Presentation dental treatment & management application project
 
Umldiagramforhospitalmanagementsystem 140425070951-phpapp02
Umldiagramforhospitalmanagementsystem 140425070951-phpapp02Umldiagramforhospitalmanagementsystem 140425070951-phpapp02
Umldiagramforhospitalmanagementsystem 140425070951-phpapp02
 
Uml diagram for_hospital_management_system
Uml diagram for_hospital_management_systemUml diagram for_hospital_management_system
Uml diagram for_hospital_management_system
 
HORIZON HI-TECH SOFT SYSTEMS
 HORIZON HI-TECH SOFT SYSTEMS HORIZON HI-TECH SOFT SYSTEMS
HORIZON HI-TECH SOFT SYSTEMS
 
Smart Health Disease Prediction django machinelearning.pptx
Smart Health Disease Prediction django machinelearning.pptxSmart Health Disease Prediction django machinelearning.pptx
Smart Health Disease Prediction django machinelearning.pptx
 
Hospital Management System Presentation
Hospital Management System PresentationHospital Management System Presentation
Hospital Management System Presentation
 
Srs hospital management
Srs hospital managementSrs hospital management
Srs hospital management
 
HI300 Unit 6 Secondary Data Sources - DiscussionSecondary Dat.docx
HI300 Unit 6 Secondary Data Sources - DiscussionSecondary Dat.docxHI300 Unit 6 Secondary Data Sources - DiscussionSecondary Dat.docx
HI300 Unit 6 Secondary Data Sources - DiscussionSecondary Dat.docx
 
In the given a database is used to.pdf
In the given a database is used to.pdfIn the given a database is used to.pdf
In the given a database is used to.pdf
 
SRS for Hospital Management System
SRS for Hospital Management SystemSRS for Hospital Management System
SRS for Hospital Management System
 
Majd
MajdMajd
Majd
 

KingsleyUsen_HospitalDatabase

  • 1. Lab Project A Hospital Database Kingsley Usen DBST651, Fall 2016 Submitted To Graduate School University of Maryland University College Date: November 27, 2016
  • 2. Statement of Work (SOW) Kingsley Usen DBST 651, FALL 2016 Overview: I will create a database to keep track of patient data for a medical facility. This database will aid in easing the flow of operations at a medical facility and provides immediate information to doctors and nurses regarding the condition of a patient Purpose and Objective: The database will enable a nurse to enter and store a patient charts and histories during a particular trip to the clinic. It stores the patient’s first and last name, age, symptoms, prescriptions for the patient, and the date the patient is admitted into the clinic. This database also keeps track of the doctors and nurses that attend to a particular patient as well as the patient diagnosis from the doctor. The charts from the nurse is used to update the doctor on the condition of the patient which in turn assists the doctor(s) in performing adequate diagnosis. The information stored in this database would be used to efficiently track the patients that are treated at the clinic, the nurse charts and history of patient’s symptoms, the doctors’ diagnosis of the patient and the date a patient gets admitted and checked out of the clinic. Diagram Tool: ER Assistant Database: Oracle 11g, using Virtual Desktop Applications (VDA) Hardware and Software: UMUC (VDA) Intel(R) Core(TM). Operating system is Windows DDL and DML: SQL (Structured Query Language) will be used to create the DDL and DML scripts. SQL would be used to translate the information captured using the ER Assistant, in an ER diagram, into
  • 3. database table creation scripts for my DDL scripts. This diagram contains the various entities, attributes and relationship that exist in this database. SQL would also be used to insert rows of data or record into the database tables for my DML scripts. It would also be used to retrieve or update a record Entity Description Entities Description PATIENT Entity Name: Patient Entity Description: patients who get treated in the hospital Main attributes of Patient: Attribute Name: Patient _ID Attribute Description: patient Identification primary identification Attribute Name: Patient _FN Attribute Description: patient first name Assistance/receives assistance Assigned/gets assigned Assignment Assignment_ID Nurse_ID_FK Doctor_ID_FK Assignment_Date Assignment_Cap Medicated/receives medecine Prescribes/prescribes medication Treats/treats patients Analysis/charts the patient Prescription Prescription_ID Doctor_ID_FK Patient_ID_FK Prescription_check Prescription_Date Prescription_Note Doctor Doctor_ID Doctor_FN Doctor_LN Doctor_Phone Doctor_SSN Patient Patient_ID Patient_FN Patient_LN Notes Doctor_ID_FK Nurse_ID_FK Nurse Nurse_ID Nurse_FN Nurse_LN Nurse_Phone Nurse_SSN
  • 4. Attribute Name: Patient _LN Attribute Description: patient last name Attribute Name: Notes Attribute Description: symptoms of patient Attribute Name: Doctor_ID_FK Attribute Description: doctor identification foreign key Attribute Name: Nurse_ID_FK Attribute Description: nurse identification foreign key DOCTOR Entity Name: Doctor Entity Description: doctors who treat patients at the hospital Main attributes of Doctor: Attribute Name: Doctor _ID Attribute Description: doctor identification primary key Attribute Name: Doctor _FN Attribute Description: doctor first name Attribute Name: Doctor _LN Attribute Description: doctor last name Attribute Name: Doctor _Phone Attribute Description: doctor phone number Attribute Name: Doctor _SSN Attribute Description: doctor social security number NURSE Entity Name: Nurse Entity Description: nurses who treat patients Main attributes of Nurse: Attribute Name: Nurse _ID Attribute Description: nurse identification primary key Attribute Name: Nurse _FN Attribute Description: nurse first name Attribute Name: Nurse _LN Attribute Description: nurse last name Attribute Name: Nurse _Phone Attribute Description: nurse phone number Attribute Name: Nurse _SSN Attribute Description: nurse social security number
  • 5. PRESCRIPTION Entity Name: Prescription Entity Description: prescriptions for patients in the hospital Main attributes of Prescription: Attribute Name: Prescription _ID Attribute Description: prescription identification primary key Attribute Name: Doctor_ID_FK Attribute Description: doctor identification foreign key Attribute Name: Patient_ID_FK Attribute Description: patient identification foreign key Attribute Name: Prescription_Check Attribute Description: checks the availability of prescriptions Attribute Name: Prescription_Note Attribute Description: lists the prescribed drugs separated by a delimiter Attribute Name: Prescription_Date Attribute Description: date a prescription was written ASSIGNMENT Entity Name: Assignment Entity Description: assignments of nurses to doctors at the hospital Main attributes of Assignment: Attribute Name: Assignment _ID Attribute Description: assignment identification primary key Attribute Name: Nurse_ID_FK Attribute Description: nurse identification foreign key Attribute Name: Doctor_ID_FK Attribute Description: doctor identification foreign key Attribute Name: Assignment_Date Attribute Description: assignment date Attribute Name: Assignment_Cap Attribute Description: assignment capacity Entity Relationship Relationship: works between PATIENT and PRESCRIPTION
  • 6. Cardinality/Business rule: a patient can receive zero to many prescriptions, a prescription is received by one and only one patient Relationship: works between DOCTOR and PATIENT Cardinality/Business rule: a doctor can treat zero to many patients, a patient gets treated by one and only one doctor Relationship: works between DOCTOR and PRESCRIPTION Cardinality/Business rule: a doctor can prescribe zero to many prescriptions, a prescription gets prescribed by one and only one doctor Relationship: works between NURSE and ASSIGNMENT Cardinality/Business rule: a nurse can have zero to many assignments, an assignment is reserved for one and only one nurse Relationship: works between DOCTOR and ASSIGNMENT Cardinality/Business rule: a doctor receives assistance from zero to many assigned nurses, an assigned nurse provides assistance to one and only one doctor Assumptions 1. A patient is only assigned one doctor throughout the duration of stay at this hospital 2. There is a cap at how many nurses can get assigned to a doctor at any time (maximum is 4). 3. The Assignment_Cap attribute in Assignment entity checks this value. If valid, then assignments can be made DDL (Data Definition Language) REM *************************************************************************** REM File: CreateHealthSystem.sql REM Description: Used for creating the objects and loading data into REM the Health System schema REM Created: November 13, 2016 REM ****************************************************************************
  • 7. PROMPT Dropping HealthSystem schema objects REM === Drop Table === DROP TABLE PATIENT CASCADE CONSTRAINTS; DROP TABLE PRESCRIPTION CASCADE CONSTRAINTS; DROP TABLE DOCTOR CASCADE CONSTRAINTS; DROP TABLE NURSE CASCADE CONSTRAINTS; DROP TABLE ASSIGNMENT CASCADE CONSTRAINTS; REM === Drop Sequences === DROP SEQUENCE PATIENT_ID_SEQ; DROP SEQUENCE DOCTOR_ID_SEQ; DROP SEQUENCE NURSE_ID_SEQ; DROP SEQUENCE PRESCRIPTION_ID_SEQ; DROP SEQUENCE ASSIGNMENT_ID_SEQ; PROMPT Creating Table 'NURSE' CREATE TABLE NURSE (NURSE_ID NUMBER(8,0) ,NURSE_FN VARCHAR2(25) ,NURSE_LN VARCHAR2(25) ,NURSE_PHONE VARCHAR2(15)
  • 8. ,NURSE_SSN VARCHAR2(11) ,CREATED_BY VARCHAR2(30) ,CREATED_DATE DATE ,MODIFIED_BY VARCHAR2(30) ,MODIFIED_DATE DATE ) / COMMENT ON TABLE NURSE IS 'Profile information for a nurse.' / COMMENT ON COLUMN NURSE.NURSE_ID IS 'The unique ID for a nurse.' / COMMENT ON COLUMN NURSE.NURSE_FN IS 'This nurse''s first name.' / COMMENT ON COLUMN NURSE.NURSE_LN IS 'The nurse''s last name.' / COMMENT ON COLUMN NURSE.NURSE_PHONE IS 'The nurse''s phone number.' / COMMENT ON COLUMN NURSE.NURSE_SSN IS 'The nurse''s social security number.'
  • 9. / COMMENT ON COLUMN NURSE.CREATED_BY IS 'Audit column - indicates user who inserted data.' / COMMENT ON COLUMN NURSE.CREATED_DATE IS 'Audit column - indicates date of insert.' / COMMENT ON COLUMN NURSE.MODIFIED_BY IS 'Audit column - indicates who made last update.' / COMMENT ON COLUMN NURSE.MODIFIED_DATE IS 'Audit column - date of last update.' / PROMPT Creating Table 'DOCTOR' CREATE TABLE DOCTOR (DOCTOR_ID NUMBER(8,0) ,DOCTOR_FN VARCHAR2(25) ,DOCTOR_LN VARCHAR2(25) ,DOCTOR_PHONE VARCHAR2(15) ,DOCTOR_SSN VARCHAR2(11) ,CREATED_BY VARCHAR2(30) ,CREATED_DATE DATE
  • 10. ,MODIFIED_BY VARCHAR2(30) ,MODIFIED_DATE DATE ) / COMMENT ON TABLE DOCTOR IS 'Profile information for a doctor.' / COMMENT ON COLUMN DOCTOR.DOCTOR_ID IS 'The unique ID for a doctor.' / COMMENT ON COLUMN DOCTOR.DOCTOR_FN IS 'This doctor''s first name.' / COMMENT ON COLUMN DOCTOR.DOCTOR_LN IS 'The doctor''s last name.' / COMMENT ON COLUMN DOCTOR.DOCTOR_PHONE IS 'The doctor''s phone number.' / COMMENT ON COLUMN DOCTOR.DOCTOR_SSN IS 'The doctor''s social security number.' /
  • 11. COMMENT ON COLUMN DOCTOR.CREATED_BY IS 'Audit column - indicates user who inserted data.' / COMMENT ON COLUMN DOCTOR.CREATED_DATE IS 'Audit column - indicates date of insert.' / COMMENT ON COLUMN DOCTOR.MODIFIED_BY IS 'Audit column - indicates who made last update.' / COMMENT ON COLUMN DOCTOR.MODIFIED_DATE IS 'Audit column - date of last update.' / PROMPT Creating Table 'PATIENT' CREATE TABLE PATIENT (PATIENT_ID NUMBER(8,0) ,PATIENT_FN VARCHAR2(25) ,PATIENT_LN VARCHAR2(25) ,PHONE VARCHAR2(15) ,NOTES VARCHAR2(2000) ,DOCTOR_ID NUMBER(8,0) ,NURSE_ID NUMBER(8,0) ,CREATED_BY VARCHAR2(30)
  • 12. ,CREATED_DATE DATE ,MODIFIED_BY VARCHAR2(30) ,MODIFIED_DATE DATE ) / COMMENT ON TABLE PATIENT IS 'Profile information for a patient.' / COMMENT ON COLUMN PATIENT.PATIENT_ID IS 'The unique ID for a patient.' / COMMENT ON COLUMN PATIENT.PATIENT_FN IS 'This patient''s first name.' / COMMENT ON COLUMN PATIENT.PATIENT_LN IS 'The patient''s last name.' / COMMENT ON COLUMN PATIENT.PHONE IS 'The patient''s phone number.' / COMMENT ON COLUMN PATIENT.DOCTOR_ID IS 'The unique ID for a doctor.' /
  • 13. COMMENT ON COLUMN PATIENT.NURSE_ID IS 'The unique ID for a nurse.' / COMMENT ON COLUMN PATIENT.CREATED_BY IS 'Audit column - indicates user who inserted data.' / COMMENT ON COLUMN PATIENT.CREATED_DATE IS 'Audit column - indicates date of insert.' / COMMENT ON COLUMN PATIENT.MODIFIED_BY IS 'Audit column - indicates who made last update.' / COMMENT ON COLUMN PATIENT.MODIFIED_DATE IS 'Audit column - date of last update.' / PROMPT Creating Table 'PRESCRIPTION' CREATE TABLE PRESCRIPTION (PRESCRIPTION_ID NUMBER(8,0) ,DOCTOR_ID NUMBER(8,0) ,PATIENT_ID NUMBER(8,0) ,PRESCRIPTION_CHECK CHAR(1) ,PRESCRIPTION_NOTE VARCHAR2(2000) ,PRESCRIPTION_DATE DATE
  • 14. ,CREATED_BY VARCHAR2(30) ,CREATED_DATE DATE ,MODIFIED_BY VARCHAR2(30) ,MODIFIED_DATE DATE ) / COMMENT ON TABLE PRESCRIPTION IS 'Prescription information for a patient.' / COMMENT ON COLUMN PRESCRIPTION.PRESCRIPTION_ID IS 'The unique ID for a prescription.' / COMMENT ON COLUMN PRESCRIPTION.DOCTOR_ID IS 'The unique ID for a doctor' / COMMENT ON COLUMN PRESCRIPTION.PATIENT_ID IS 'The unique ID of a patient' / COMMENT ON COLUMN PRESCRIPTION.PRESCRIPTION_CHECK IS 'Used to check if prescriptions are available' / COMMENT ON COLUMN PRESCRIPTION.PRESCRIPTION_DATE IS 'The date the prescription is to be received'
  • 15. / COMMENT ON COLUMN PRESCRIPTION.CREATED_BY IS 'Audit column - indicates user who inserted data.' / COMMENT ON COLUMN PRESCRIPTION.CREATED_DATE IS 'Audit column - indicates date of insert.' / COMMENT ON COLUMN PRESCRIPTION.MODIFIED_BY IS 'Audit column - indicates who made last update.' / COMMENT ON COLUMN PRESCRIPTION.MODIFIED_DATE IS 'Audit column - date of last update.' / PROMPT Creating Table 'ASSIGNMENT' CREATE TABLE ASSIGNMENT (ASSIGNMENT_ID NUMBER(8,0) ,NURSE_ID NUMBER(8,0) ,DOCTOR_ID NUMBER(8,0) ,ASSIGNMENT_DATE DATE ,ASSIGNMENT_CAP CHAR(1)
  • 16. ,CREATED_BY VARCHAR2(30) ,CREATED_DATE DATE ,MODIFIED_BY VARCHAR2(30) ,MODIFIED_DATE DATE ) / COMMENT ON TABLE ASSIGNMENT IS 'Used to assign nurses to doctors' / COMMENT ON COLUMN ASSIGNMENT.ASSIGNMENT_ID IS 'The unique ID for an assignmet.' / COMMENT ON COLUMN ASSIGNMENT.NURSE_ID IS 'This unique ID for a nurse.' / COMMENT ON COLUMN ASSIGNMENT.DOCTOR_ID IS 'The unique ID for a doctor' / COMMENT ON COLUMN ASSIGNMENT.ASSIGNMENT_DATE IS 'The date of an assignment' / COMMENT ON COLUMN ASSIGNMENT.ASSIGNMENT_CAP IS 'Used to check if an assignment is full F or incomplete I'
  • 17. / COMMENT ON COLUMN ASSIGNMENT.CREATED_BY IS 'Audit column - indicates user who inserted data.' / COMMENT ON COLUMN ASSIGNMENT.CREATED_DATE IS 'Audit column - indicates date of insert.' / COMMENT ON COLUMN ASSIGNMENT.MODIFIED_BY IS 'Audit column - indicates who made last update.' / COMMENT ON COLUMN ASSIGNMENT.MODIFIED_DATE IS 'Audit column - date of last update.' / -- PROMPT healthsystem.ind PROMPT Creating Unique Index 'NUR_NUR_SSN' CREATE UNIQUE INDEX NUR_NURSE_SSN_UX ON NURSE (NURSE_SSN) / PROMPT Creating Unique Index 'DOC_DOC_SSN'
  • 18. CREATE UNIQUE INDEX DOC_DOC_SSN_UX ON DOCTOR (DOCTOR_SSN) / PROMPT Creating Index 'PRE_PAT_FK_I' CREATE INDEX PRE_PAT_FK_I ON PRESCRIPTION (PATIENT_ID) / PROMPT Creating Index 'PRE_DOC_FK_I' CREATE INDEX PRE_DOC_FK_I ON PRESCRIPTION (DOCTOR_ID) / PROMPT Creating Index 'PAT_DOC_FK_I' CREATE INDEX PAT_DOC_FK_I ON PATIENT (DOCTOR_ID) / PROMPT Creating Index 'ASS_DOC_FK_I' CREATE INDEX ASS_DOC_FK_I ON ASSIGNMENT (DOCTOR_ID) / PROMPT Creating Index 'ASS_NUR_FK_I' CREATE INDEX ASS_NUR_FK_I ON ASSIGNMENT (NURSE_ID) / PROMPT Creating Index 'PAT_NUR_FK_I'
  • 19. CREATE INDEX PAT_NUR_FK_I ON PATIENT (NURSE_ID) / PROMPT Creating Index 'PAT_PATIENT_LN_IDX' CREATE INDEX PAT_PATIENT_LN_IDX ON PATIENT (PATIENT_LN) / PROMPT Creating Index 'NUR_NURSE_LN_IDX' CREATE INDEX NUR_NURSE_LN_IDX ON NURSE (NURSE_LN) / PROMPT Creating Index 'DOC_DOCTOR_LN_IDX' CREATE INDEX DOCTOR_DOCTOR_LN_IDX ON DOCTOR (DOCTOR_LN) / -- PROMPT healthsystem.con PROMPT Creating Check Constraints on 'PATIENT' ALTER TABLE PATIENT MODIFY(PATIENT_ID CONSTRAINT PAT_PATIENT_ID_NNULL NOT NULL) MODIFY(DOCTOR_ID CONSTRAINT PAT_DOCTOR_ID_NNULL NOT NULL) MODIFY(NURSE_ID CONSTRAINT PAT_NURSE_ID_NNULL NOT NULL) MODIFY(MODIFIED_BY CONSTRAINT PAT_MODIFIED_BY_NNULL NOT NULL)
  • 20. MODIFY(CREATED_BY CONSTRAINT PAT_CREATED_BY_NNULL NOT NULL) MODIFY(MODIFIED_DATE CONSTRAINT PAT_MODIFIED_DATE_NNULL NOT NULL) MODIFY(CREATED_DATE CONSTRAINT PAT_CREATED_DATE_NNULL NOT NULL) / PROMPT Creating Check Constraints on 'PRESCRIPTION' ALTER TABLE PRESCRIPTION MODIFY(PRESCRIPTION_ID CONSTRAINT PRE_PRESCRIPTION_ID_NNULL NOT NULL) MODIFY(PATIENT_ID CONSTRAINT PRE_PATIENT_ID_NNULL NOT NULL) MODIFY(DOCTOR_ID CONSTRAINT PRE_DOCTOR_ID_NNULL NOT NULL) MODIFY(PRESCRIPTION_CHECK CONSTRAINT PRE_PRESCRIPTION_CHECK_NNULL NOT NULL) MODIFY(MODIFIED_BY CONSTRAINT PRE_MODIFIED_BY_NNULL NOT NULL) MODIFY(CREATED_BY CONSTRAINT PRE_CREATED_BY_NNULL NOT NULL) MODIFY(MODIFIED_DATE CONSTRAINT PRE_MODIFIED_DATE_NNULL NOT NULL) MODIFY(CREATED_DATE CONSTRAINT PRE_CREATED_DATE_NNULL NOT NULL) ADD CONSTRAINT PRE_PRESCRIPTION_CHECK_LENGTH CHECK (LENGTH(prescription_check)=1) / PROMPT Creating Check Constraints on 'DOCTOR' ALTER TABLE DOCTOR MODIFY(DOCTOR_ID CONSTRAINT DOC_DOCTOR_ID_NNULL NOT NULL) MODIFY(DOCTOR_LN CONSTRAINT DOC_DOCTOR_LN_NNULL NOT NULL) MODIFY(MODIFIED_BY CONSTRAINT DOC_MODIFIED_BY_NNULL NOT NULL)
  • 21. MODIFY(CREATED_BY CONSTRAINT DOC_CREATED_BY_NNULL NOT NULL) MODIFY(MODIFIED_DATE CONSTRAINT DOC_MODIFIED_DATE_NNULL NOT NULL) MODIFY(CREATED_DATE CONSTRAINT DOC_CREATED_DATE_NNULL NOT NULL) / PROMPT Creating Check Constraints on 'ASSIGNMENT' ALTER TABLE ASSIGNMENT MODIFY(ASSIGNMENT_ID CONSTRAINT ASS_ASSIGNMENT_ID_NNULL NOT NULL) MODIFY(DOCTOR_ID CONSTRAINT ASS_DOCTOR_ID_NNULL NOT NULL) MODIFY(NURSE_ID CONSTRAINT ASS_NURSE_ID_NNULL NOT NULL) MODIFY(ASSIGNMENT_CAP CONSTRAINT ASS_ASSIGNMENT_CAP_NNULL NOT NULL) MODIFY(MODIFIED_BY CONSTRAINT ASS_MODIFIED_BY_NNULL NOT NULL) MODIFY(CREATED_BY CONSTRAINT ASS_CREATED_BY_NNULL NOT NULL) MODIFY(MODIFIED_DATE CONSTRAINT ASS_MODIFIED_DATE_NNULL NOT NULL) MODIFY(CREATED_DATE CONSTRAINT ASS_CREATED_DATE_NNULL NOT NULL) ADD CONSTRAINT ASS_ASSIGNMENT_CAP_LENGTH CHECK (LENGTH(assignment_cap)=1) / PROMPT Creating Check Constraints on 'NURSE' ALTER TABLE NURSE MODIFY(NURSE_ID CONSTRAINT NUR_NURSE_ID_NNULL NOT NULL) MODIFY(NURSE_LN CONSTRAINT NUR_NURSE_LN_NNULL NOT NULL) MODIFY(MODIFIED_BY CONSTRAINT NUR_MODIFIED_BY_NNULL NOT NULL) MODIFY(CREATED_BY CONSTRAINT NUR_CREATED_BY_NNULL NOT NULL)
  • 22. MODIFY(MODIFIED_DATE CONSTRAINT NUR_MODIFIED_DATE_NNULL NOT NULL) MODIFY(CREATED_DATE CONSTRAINT NUR_CREATED_DATE_NNULL NOT NULL) / PROMPT Creating Primary Key on 'PATIENT' ALTER TABLE PATIENT ADD CONSTRAINT PAT_PK PRIMARY KEY (PATIENT_ID) / PROMPT Creating Primary Key on 'PRESCRIPTION' ALTER TABLE PRESCRIPTION ADD CONSTRAINT PRE_PK PRIMARY KEY (PRESCRIPTION_ID) / PROMPT Creating Primary Key on 'DOCTOR' ALTER TABLE DOCTOR ADD CONSTRAINT DOC_PK PRIMARY KEY (DOCTOR_ID) / PROMPT Creating Primary Key on 'NURSE' ALTER TABLE NURSE ADD CONSTRAINT NUR_PK PRIMARY KEY (NURSE_ID) /
  • 23. PROMPT Creating Primary Key on 'ASSIGNMENT' ALTER TABLE ASSIGNMENT ADD CONSTRAINT ASS_PK PRIMARY KEY (ASSIGNMENT_ID, NURSE_ID, DOCTOR_ID) / PROMPT Creating Foreign Keys on 'PATIENT' ALTER TABLE PATIENT ADD CONSTRAINT PAT_DOC_FK FOREIGN KEY (DOCTOR_ID) REFERENCES DOCTOR (DOCTOR_ID) ADD CONSTRAINT PAT_NUR_FK FOREIGN KEY (NURSE_ID) REFERENCES NURSE (NURSE_ID) / PROMPT Creating Foreign Keys on 'PRESCRIPTION' ALTER TABLE PRESCRIPTION ADD CONSTRAINT PRE_PAT_FK FOREIGN KEY (PATIENT_ID) REFERENCES PATIENT (PATIENT_ID) ADD CONSTRAINT PRE_DOC_FK FOREIGN KEY (DOCTOR_ID) REFERENCES DOCTOR (DOCTOR_ID)
  • 24. / PROMPT Creating Foreign Keys on 'ASSIGNMENT' ALTER TABLE ASSIGNMENT ADD CONSTRAINT ASS_DOC_FK FOREIGN KEY (DOCTOR_ID) REFERENCES DOCTOR (DOCTOR_ID) ADD CONSTRAINT ASS_NUR_FK FOREIGN KEY (NURSE_ID) REFERENCES NURSE (NURSE_ID) / -- PROMPT healthsystem.sqs PROMPT Creating Sequence 'PATIENT_ID_SEQ' CREATE SEQUENCE PATIENT_ID_SEQ INCREMENT BY 1 START WITH 300 NOMAXVALUE MINVALUE 1 NOCYCLE NOCACHE /
  • 25. PROMPT Creating Sequence 'DOCTOR_ID_SEQ' CREATE SEQUENCE DOCTOR_ID_SEQ INCREMENT BY 1 START WITH 500 NOMAXVALUE MINVALUE 1 NOCYCLE NOCACHE / PROMPT Creating Sequence 'NURSE_ID_SEQ' CREATE SEQUENCE NURSE_ID_SEQ INCREMENT BY 1 START WITH 600 NOMAXVALUE MINVALUE 1 NOCYCLE NOCACHE / PROMPT Creating Sequence 'PRESCRIPTION_ID_SEQ' CREATE SEQUENCE PRESCRIPTION_ID_SEQ INCREMENT BY 1 START WITH 100
  • 26. NOMAXVALUE MINVALUE 1 NOCYCLE NOCACHE / PROMPT Creating Sequence 'ASSIGNMENT_ID_SEQ' CREATE SEQUENCE ASSIGNMENT_ID_SEQ INCREMENT BY 1 START WITH 222 NOMAXVALUE MINVALUE 1 NOCYCLE NOCACHE / -- PROMPT healthsystem.vw PROMPT Creating View 'VW_PAT' CREATE OR REPLACE VIEW VW_PAT AS SELECT PATIENT_ID, PATIENT_FN, PATIENT_LN, PHONE, NOTES, DOCTOR_ID, NURSE_ID FROM PATIENT /
  • 27. PROMPT Creating View 'VW_DOC' CREATE OR REPLACE VIEW VW_DOC AS SELECT DOCTOR_ID, DOCTOR_FN, DOCTOR_LN, DOCTOR_PHONE, DOCTOR_SSN FROM DOCTOR / PROMPT Creating View 'VW_NUR' CREATE OR REPLACE VIEW VW_NUR AS SELECT NURSE_ID, NURSE_FN, NURSE_LN, NURSE_PHONE, NURSE_SSN FROM NURSE / PROMPT Creating View 'VW_PRE' CREATE OR REPLACE VIEW VW_PRE AS SELECT PRESCRIPTION_ID, DOCTOR_ID, PATIENT_ID, PRESCRIPTION_CHECK, PRESCRIPTION_NOTE PRESCRIPTION_DATE FROM PRESCRIPTION / PROMPT Creating View 'VW_ASS' CREATE OR REPLACE VIEW VW_ASS AS SELECT ASSIGNMENT_ID, NURSE_ID, DOCTOR_ID, ASSIGNMENT_DATE, ASSIGNMENT_CAP FROM ASSIGNMENT /
  • 28. -- PROMPT healthsystem.tri PROMPT Creating Trigger 'BIUR_PAT_TRG' CREATE OR REPLACE TRIGGER BIUR_PAT_TRG BEFORE INSERT OR UPDATE ON PATIENT FOR EACH ROW BEGIN IF :NEW.patient_id IS NULL THEN :NEW.patient_id :=PATIENT_ID_SEQ.NEXTVAL; END IF; IF INSERTING THEN IF :NEW.created_by IS NULL THEN :NEW.created_by := USER; END IF; IF :NEW.created_date IS NULL THEN :NEW.created_date :=SYSDATE; END IF; END IF; IF INSERTING OR UPDATING THEN IF :NEW.modified_by IS NULL THEN :NEW.modified_by := USER; END IF; IF :NEW.modified_date IS NULL THEN :NEW.modified_date := SYSDATE; END IF; END IF; END; / PROMPT Creating Trigger 'BIUR_DOC_TRG' CREATE OR REPLACE TRIGGER BIUR_DOC_TRG BEFORE INSERT OR UPDATE ON DOCTOR
  • 29. FOR EACH ROW BEGIN IF :NEW.doctor_id IS NULL THEN :NEW.doctor_id := DOCTOR_ID_SEQ.NEXTVAL; END IF; IF INSERTING THEN IF :NEW.created_by IS NULL THEN :NEW.created_by := USER; END IF; IF :NEW.created_date IS NULL THEN :NEW.created_date :=SYSDATE; END IF; END IF; IF INSERTING OR UPDATING THEN IF :NEW.modified_by IS NULL THEN :NEW.modified_by := USER; END IF; IF :NEW.modified_date IS NULL THEN :NEW.modified_date := SYSDATE; END IF; END IF; END; / PROMPT Creating Trigger 'BIUR_NUR_TRG' CREATE OR REPLACE TRIGGER BIUR_NUR_TRG BEFORE INSERT OR UPDATE ON NURSE FOR EACH ROW BEGIN IF :NEW.nurse_id IS NULL THEN :NEW.nurse_id := NURSE_ID_SEQ.NEXTVAL; END IF;
  • 30. IF INSERTING THEN IF :NEW.created_by IS NULL THEN :NEW.created_by := USER; END IF; IF :NEW.created_date IS NULL THEN :NEW.created_date :=SYSDATE; END IF; END IF; IF INSERTING OR UPDATING THEN IF :NEW.modified_by IS NULL THEN :NEW.modified_by := USER; END IF; IF :NEW.modified_date IS NULL THEN :NEW.modified_date := SYSDATE; END IF; END IF; END; / PROMPT Creating Trigger 'BIUR_PRE_TRG' CREATE OR REPLACE TRIGGER BIUR_PRE_TRG BEFORE INSERT OR UPDATE ON PRESCRIPTION FOR EACH ROW BEGIN IF :NEW.prescription_id IS NULL THEN :NEW.prescription_id :=PRESCRIPTION_ID_SEQ.NEXTVAL; END IF; IF INSERTING THEN IF :NEW.created_by IS NULL THEN :NEW.created_by := USER; END IF; IF :NEW.created_date IS NULL THEN :NEW.created_date :=SYSDATE; END IF; IF :NEW.prescription_date IS NULL THEN :NEW.prescription_date :=SYSDATE; END IF; END IF;
  • 31. IF INSERTING OR UPDATING THEN IF :NEW.modified_by IS NULL THEN :NEW.modified_by := USER; END IF; IF :NEW.modified_date IS NULL THEN :NEW.modified_date := SYSDATE; END IF; END IF; END; / PROMPT Creating Trigger 'BIUR_ASS_TRG' CREATE OR REPLACE TRIGGER BIUR_ASS_TRG BEFORE INSERT OR UPDATE ON ASSIGNMENT FOR EACH ROW BEGIN IF :NEW.assignment_id IS NULL THEN :NEW.assignment_id :=ASSIGNMENT_ID_SEQ.NEXTVAL; END IF; IF INSERTING THEN IF :NEW.created_by IS NULL THEN :NEW.created_by := USER; END IF; IF :NEW.created_date IS NULL THEN :NEW.created_date :=SYSDATE; END IF; IF :NEW.assignment_date IS NULL THEN :NEW.assignment_date :=SYSDATE; END IF; END IF; IF INSERTING OR UPDATING THEN IF :NEW.modified_by IS NULL THEN :NEW.modified_by := USER; END IF; IF :NEW.modified_date IS NULL THEN :NEW.modified_date := SYSDATE; END IF; END IF;
  • 32. END; / SET ECHO OFF PROMPT ** ****************************************************** ** PROMPT ** Checking the DBMS data dictionary to verify successful ** PROMPT ** creationg of database objects. ** PROMPT ** ****************************************************** ** SET ECHO OFF SET PAGES 0 DML (Data Manipulation Language) -- PROMPT insertNUR.sql INSERT INTO Nurse (Nurse_FN, Nurse_LN, Nurse_Phone, Nurse_SSN) VALUES ('Obehi','Ukpebor', '2403159874', '223-45-9005'); INSERT INTO Nurse (Nurse_FN, Nurse_LN, Nurse_Phone, Nurse_SSN) VALUES ('Bukky','Saula', '3015469874', '301-59-0015'); INSERT INTO Nurse (Nurse_FN, Nurse_LN, Nurse_Phone, Nurse_SSN) VALUES ('Abdul','Olawin', '3019874569', '987-99-3465'); INSERT INTO Nurse (Nurse_FN, Nurse_LN, Nurse_Phone, Nurse_SSN) VALUES ('Adaeze','Gold', '7574189625', '205-70-9685'); INSERT INTO Nurse (Nurse_FN, Nurse_LN, Nurse_Phone, Nurse_SSN) VALUES ('Sharon','Heather', '2406941268', '789-67-7012'); INSERT INTO Nurse (Nurse_FN, Nurse_LN, Nurse_Phone, Nurse_SSN) VALUES ('Cyndy','Watsons', '7574181258', '801-34-9745'); INSERT INTO Nurse (Nurse_FN, Nurse_LN, Nurse_Phone, Nurse_SSN) VALUES ('Mercy','Johnson', '2406940937', '888-16-9863');
  • 33. INSERT INTO Nurse (Nurse_FN, Nurse_LN, Nurse_Phone, Nurse_SSN) VALUES ('Josephine','Sawyer', '3017891268', '705-62-3698'); INSERT INTO Nurse (Nurse_FN, Nurse_LN, Nurse_Phone, Nurse_SSN) VALUES ('Victoria','Abigail', '3015691268', '968-99-2894'); INSERT INTO Nurse (Nurse_FN, Nurse_LN, Nurse_Phone, Nurse_SSN) VALUES ('Sarah','Watsons', '7576941268', '756-73-4856'); COMMIT; -- PROMPT insertDOC.sql INSERT INTO Doctor (Doctor_FN, Doctor_LN, Doctor_Phone, Doctor_SSN) VALUES ('Adam','Sandler', '2403159874', '201-45-9875'); INSERT INTO Doctor (Doctor_FN, Doctor_LN, Doctor_Phone, Doctor_SSN) VALUES ('Mark','Wahlberg', '3012545698', '325-98-1256'); INSERT INTO Doctor (Doctor_FN, Doctor_LN, Doctor_Phone, Doctor_SSN) VALUES ('Dwayne','Johnson', '2405146987', '888-45-9862'); INSERT INTO Doctor (Doctor_FN, Doctor_LN, Doctor_Phone, Doctor_SSN) VALUES ('Kevin','Hart', '2404658978', '251-98-7894'); INSERT INTO Doctor (Doctor_FN, Doctor_LN, Doctor_Phone, Doctor_SSN) VALUES ('James','Bond', '2409685789', '240-12-0590'); INSERT INTO Doctor (Doctor_FN, Doctor_LN, Doctor_Phone, Doctor_SSN) VALUES ('Harry','Potter', '3012546987', '322-98-9775'); INSERT INTO Doctor (Doctor_FN, Doctor_LN, Doctor_Phone, Doctor_SSN) VALUES ('Michael','Owens', '3012147895', '298-68-0205'); INSERT INTO Doctor (Doctor_FN, Doctor_LN, Doctor_Phone, Doctor_SSN) VALUES ('Jennifer','Lopez', '2403198745', '301-40-9700'); INSERT INTO Doctor (Doctor_FN, Doctor_LN, Doctor_Phone, Doctor_SSN) VALUES ('Mary','Dillehad', '7576984563', '800-36-9862'); INSERT INTO Doctor (Doctor_FN, Doctor_LN, Doctor_Phone, Doctor_SSN) VALUES ('Elizabeth','Swan', '3012547896', '701-36-9865'); COMMIT;
  • 34. -- PROMPT insertPAT.sql INSERT INTO Patient (Patient_FN, Patient_LN, Phone, Notes, Doctor_ID, Nurse_ID) VALUES ('John- Bosco','Cotley', '3012569874', 'Elevated blood pressure. Symptoms getting worst.', 503, 603); INSERT INTO Patient (Patient_FN, Patient_LN, Phone, Notes, Doctor_ID, Nurse_ID) VALUES ('Sandra','Opone', '3406985452', 'Recovering. Needs more supervision.', 506, 606); INSERT INTO Patient (Patient_FN, Patient_LN, Phone, Notes, Doctor_ID, Nurse_ID) VALUES ('Miley','Cyrus', '3012563214', 'Neck pain. Stomach upset.', 503, 601); INSERT INTO Patient (Patient_FN, Patient_LN, Phone, Notes, Doctor_ID, Nurse_ID) VALUES ('Joshua','Ali', '2409856321', 'Responding well to treatment. Minmal supervision required.', 506, 607); INSERT INTO Patient (Patient_FN, Patient_LN, Phone, Notes, Doctor_ID, Nurse_ID) VALUES ('Bobo','Usen', '2026563652', 'Reacts to chloroquine and peptol.', 507, 602); INSERT INTO Patient (Patient_FN, Patient_LN, Phone, Notes, Doctor_ID, Nurse_ID) VALUES ('Hannah','Montana', '3015262463', 'High blood pressure, lower leg pain.', 509, 608); INSERT INTO Patient (Patient_FN, Patient_LN, Phone, Notes, Doctor_ID, Nurse_ID) VALUES ('Elliot','Carmelo', '7579860937', 'More supervision needed. Not reacting to medication.', 508, 604); INSERT INTO Patient (Patient_FN, Patient_LN, Phone, Notes, Doctor_ID, Nurse_ID) VALUES ('Matthew','Wilson', '3016987412', 'Stomach upset and constipation.', 502, 605); INSERT INTO Patient (Patient_FN, Patient_LN, Phone, Notes, Doctor_ID, Nurse_ID) VALUES ('Sugar','Wilslow', '2403012569', 'Toe fracture.', 502, 608); INSERT INTO Patient (Patient_FN, Patient_LN, Phone, Notes, Doctor_ID, Nurse_ID) VALUES ('Fahrdad','Gushavi', '8886981268', 'Knee dislocated. Non-stop bleeding', 509, 609); COMMIT; -- PROMPT insertPRE.sql INSERT INTO Prescription (Doctor_ID, Patient_ID, Prescription_Check, Prescription_Note) VALUES (506, 302, 'Y', 'Bystolic-Oxycontin'); INSERT INTO Prescription (Doctor_ID, Patient_ID, Prescription_Check, Prescription_Note) VALUES (506, 301, 'N', 'Bystolic-Nexium-Advil'); INSERT INTO Prescription (Doctor_ID, Patient_ID, Prescription_Check, Prescription_Note) VALUES (506, 303, 'Y', 'Tylenol-Bystolic-Tylenol');
  • 35. INSERT INTO Prescription (Doctor_ID, Patient_ID, Prescription_Check, Prescription_Note) VALUES (502, 308, 'Y', 'Advil-Pepsid'); INSERT INTO Prescription (Doctor_ID, Patient_ID, Prescription_Check, Prescription_Note) VALUES (500, 300, 'N', 'Celebrex-Oxycontin-Amoxil'); INSERT INTO Prescription (Doctor_ID, Patient_ID, Prescription_Check, Prescription_Note) VALUES (501, 309, 'Y', 'Nasonex-Panadol'); INSERT INTO Prescription (Doctor_ID, Patient_ID, Prescription_Check, Prescription_Note) VALUES (501, 306, 'N', 'Flovent-Oxycontin'); INSERT INTO Prescription (Doctor_ID, Patient_ID, Prescription_Check, Prescription_Note) VALUES (507, 307, 'N', 'Amoxil-Bystolic-Pepsid'); INSERT INTO Prescription (Doctor_ID, Patient_ID, Prescription_Check, Prescription_Note) VALUES (507, 305, 'Y', 'Piriton-Novagen'); INSERT INTO Prescription (Doctor_ID, Patient_ID, Prescription_Check, Prescription_Note) VALUES (507, 304, 'Y', 'Advil'); COMMIT; -- PROMPT insertASS.sql INSERT INTO Assignment (Nurse_ID, Doctor_ID, Assignment_Cap) VALUES (602, 504, '1'); INSERT INTO Assignment (Nurse_ID, Doctor_ID, Assignment_Cap) VALUES (602, 502, '2'); INSERT INTO Assignment (Nurse_ID, Doctor_ID, Assignment_Cap) VALUES (609, 500, '1'); INSERT INTO Assignment (Nurse_ID, Doctor_ID, Assignment_Cap) VALUES (607, 505, '3'); INSERT INTO Assignment (Nurse_ID, Doctor_ID, Assignment_Cap) VALUES (607, 506, '1'); INSERT INTO Assignment (Nurse_ID, Doctor_ID, Assignment_Cap) VALUES (601, 507, '4'); INSERT INTO Assignment (Nurse_ID, Doctor_ID, Assignment_Cap) VALUES (604, 507, '4'); INSERT INTO Assignment (Nurse_ID, Doctor_ID, Assignment_Cap) VALUES (605, 502, '2'); INSERT INTO Assignment (Nurse_ID, Doctor_ID, Assignment_Cap) VALUES (605, 505, '3'); INSERT INTO Assignment (Nurse_ID, Doctor_ID, Assignment_Cap) VALUES (603, 501, '1'); COMMIT;
  • 36. DML (Data Manipulation Language) /**--1. Select all columns and all rows from Patient.*/ SELECT * FROM Patient; /**--2. Select 5 columns and all rows from one Doctor.*/ SELECT Doctor_FN, Doctor_LN, Doctor_Phone, Created_By, Modified_By From Doctor;
  • 37. /**--3. Select all columns and all rows from VW_NUR.*/ SELECT * FROM VW_NUR; /**--4. Using a join on 2 tables, select all columns and all rows from the tables without the use of a Cartesian product. */ SELECT * FROM Nurse INNER JOIN Patient ON Nurse.Nurse_ID = Patient.Nurse_ID; /**--5. Select and order data retrieved from one Prescription.*/
  • 38. SELECT * FROM Prescription ORDER BY Doctor_ID ASC; /**--6. Using a join on 3 tables, select 5 columns from the 3 tables. Use syntax that would limit the output to 10 rows. */ SELECT Patient.Patient_FN, Patient.Patient_LN, Patient.Notes, Nurse.Nurse_LN, Doctor.Doctor_LN FROM Patient INNER JOIN Doctor ON Doctor.Doctor_ID = Patient.Doctor_ID INNER JOIN Nurse ON Nurse.Nurse_ID = Patient.Nurse_ID; /**--7. Select distinct rows using joins on 3 tables. */ SELECT DISTINCT Patient.Patient_FN, Patient.Patient_LN, Prescription.Prescription_Note, Doctor.Doctor_LN FROM Prescription INNER JOIN Doctor ON Doctor.Doctor_ID = Prescription.Doctor_ID INNER JOIN Patient ON Patient.Patient_ID = Prescription.Patient_ID;
  • 39. /**--8. Use GROUP BY & HAVING in a select statement using one or more tables.*/ SELECT DISTINCT Patient.Patient_FN, Patient.Patient_LN, Doctor.Doctor_LN, Patient.Doctor_ID, Count(Patient.Doctor_ID) AS DoctorCount FROM Patient INNER JOIN Doctor ON Doctor.Doctor_ID = Patient.Doctor_ID GROUP BY Patient.Patient_FN, Patient.Patient_LN, Doctor.Doctor_LN, Patient.Doctor_ID HAVING COUNT(Patient.Doctor_ID) = 1; /**--9. Use IN clause to select data from one or more tables.*/ SELECT Patient.Patient_FN, Patient.Patient_LN, Doctor.Doctor_LN FROM Patient INNER JOIN Doctor ON Patient.Doctor_ID = Doctor.Doctor_ID WHERE Doctor.Doctor_ID IN
  • 40. (SELECT Doctor.Doctor_ID FROM Doctor WHERE Doctor.Doctor_LN = 'Lopez'); /**--10. Select length of one column from one table (use LENGTH function).*/ SELECT Prescription_ID, Prescription_Check, LENGTH(Prescription_Note) AS PrescLength From Prescription; /**--11. Use the SQL DELETE statement to delete one record from one table. Add select statements to demonstrate the table contents before and after the DELETE statement. Make sure to use ROLLBACK afterwards so that the data will not be physically removed.*/ SELECT * FROM Prescription; DELETE FROM Prescription WHERE Prescription_Note = 'Advil'; SELECT * FROM Prescription; ROLLBACK; SELECT * FROM Prescription;
  • 41. /**--12. Use the SQL UPDATE statement to change some data. Add select statements to demonstrate the table contents before and after the UPDATE statement. You can either COMMIT or ROLLBACK afterwards.*/ SELECT * FROM Patient; UPDATE Patient SET Notes = 'Toe dislocation' WHERE Patient_LN = 'Wilslow'; SELECT * FROM Patient; ROLLBACK;
  • 42. /**--13. Display the doctor's and patient's last name, along with the patient notes (Doctor_LN, Patient_LN, Notes)*/ SELECT Doctor.Doctor_LN, Patient.Patient_LN, Patient.Notes FROM Prescription INNER JOIN Doctor ON Prescription.Doctor_ID = Doctor.Doctor_ID INNER JOIN Patient ON Prescription.Patient_ID = Patient.Patient_ID WHERE Prescription.Patient_ID IN (SELECT Patient.Patient_ID FROM Patient WHERE Patient.Patient_LN = 'Opone');
  • 43. /**--14. Display the Nurse's last name and assignment cap along with its count*/ SELECT Nurse.Nurse_LN, Assignment.Assignment_Cap, Count(Assignment.Doctor_ID) AS Doctor_Cap FROM Assignment INNER JOIN Nurse ON Nurse.Nurse_ID = Assignment.Nurse_ID GROUP BY Nurse.Nurse_LN, Assignment.Assignment_Cap; /**--15. Display the nurses (last name only) who have an assignment capacity of 4*/ SELECT Nurse.Nurse_LN, Assignment.Assignment_Cap FROM Nurse INNER JOIN Assignment ON Nurse.Nurse_ID = Assignment.Nurse_ID WHERE Assignment.Doctor_ID = 507; /**--16. Show the Date a prescription was checked along with the patients name*/ SELECT Prescription.Prescription_Date, Patient.Patient_FN, Patient.Patient_LN FROM Patient INNER JOIN Prescription ON Patient.Patient_ID = Prescription.Patient_ID WHERE Patient.Patient_LN = 'Usen';
  • 44. /**--17. Show the doctors and nurses who took care of Bobo Usen */ SELECT Nurse.Nurse_FN, Nurse.Nurse_LN, Patient.Patient_FN, Patient.Patient_LN, Doctor.Doctor_FN, Doctor.Doctor_LN FROM Patient INNER JOIN Doctor ON Patient.Doctor_ID = Doctor.Doctor_ID INNER JOIN Nurse ON Patient.Nurse_ID = Nurse.Nurse_ID WHERE Nurse.Nurse_ID IN (SELECT Nurse.Nurse_ID FROM Nurse WHERE Nurse.Nurse_LN = 'Olawin'); /**--18. Assign a nurse to help doctors with less than two patients */ SELECT * FROM Assignment; UPDATE Assignment SET Assignment.Nurse_ID = 602 WHERE Assignment.Assignment_CAP < 2; SELECT * FROM Assignment; ROLLBACK; SELECT * FROM Assignment;
  • 45. /**--19. Find out all the patients who have all the prescription requirements fufulled*/ SELECT Patient.Patient_FN, Patient.Patient_LN, Prescription.Prescription_Check FROM Patient INNER JOIN Prescription ON Patient.Patient_ID = Prescription.Patient_ID WHERE Prescription.Prescription_Check = 'Y';