Database Management System Cycle 1 Hospital Database

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 49

Name Subhojit Ganguly

Registration number 19BCE0082

DATABASE MANAGEMENT SYSTEM


CYCLE 1
HOSPITAL DATABASE

Program: B.Tech
Course: CSE2004 – DBMS Database Management Systems Lab

CSE2004
1. Create all tables in Hospital database as per the requirement given below;
a) The primary key for each table to be created as specified (refer database)
b) Appropriate data type and size should be chosen for each attribute
c) Appropriate integrity constraints should be used while creating tables (NULL, NOT NULL,
FOREIGN KEY, CHECK)
d) The values for some attributes should be as follows; include appropriate CHECK constraints
to achieve them.
i) Primary key values should be created with uniformity. For example, Doc_ID can be like
‘D0001’ [five characters long and start with ‘D’], Staff_ID like ‘S0001’, Pres_ID like ‘PR00001’
and so on.
ii) Attributes and permitted values (you can decide and include such values wherever
required)

2. Populate each table with appropriate, valid and meaningful data.


3. Add some attributes with few tables and justify the additions

4. Write DML queries to achieve the following;

a) Find the details of all doctors.


b) Display all the hospital bill details.
c) List the doctors who are specialized in ‘Cardiology’ and ‘Neurology’
d) List all the appointments made for consultation room number 111, on ’11-Jan2020’
e) Display all the test types that have the values in the range of 25 and 75.
f) Find the diagnosis details of the patient with prescription id ‘PR00012’.
g) Display the name of the patients whose gender is female or the contact number is 9878987890.
H)Find the staff name and staff id who are not working in the department ‘D102’
i) Find the patients who are admitted on ’01-May-2020’ in the bed 100.
j) Delete the test results that are ‘Positive’
k) Increase the discount with 5% more for all the patients whose bill amount is greater than 100000.
l) Change the HOD of cardiology department with doctor ‘D0003’
m) Delete the prescribed medicines records that have the brand name ‘XYZ’
n) Modify the low value and high value to 10 and 30 respectively for the clinical test ‘urine’
o) Update the contact number of all staffs who are in the category ‘Nurse’
p) Delete the staff records that have designations ‘junior attender’ or ‘technician’ and belongs to the
department ‘D190’.
(Since children of table staff have foreign keys that are a part of the table Staff,Oracle refuses to
delete the row from those tables exist).

Code for creating and inserting into tables:

create table Doctor (

Doc_ID varchar(5) NOT NULL PRIMARY KEY,

Doc_Name varchar(15) NOT NULL UNIQUE,

Gender char,

DOB date,

Specialist varchar(20),

Qualification varchar(5),

Contact number(7),

Address varchar(10),
Dept_No varchar(4));

create table Department(

Dept_No varchar(4) NOT NULL PRIMARY KEY,

Dept_Name varchar(25),

Room_No varchar(3) UNIQUE,

Floor number,

HOD varchar(5),

Estd_Date date,

constraint fkey1 foreign key(HOD) references Doctor(Doc_ID));

create table Staff (

Staff_ID varchar(5) NOT NULL PRIMARY KEY,

Staff_Name varchar(10),

Category varchar(15),

Designation varchar(25) ,

DOB date,

Contact number(10),

Address varchar(10),

Dept_No varchar(4),

constraint dep foreign key(Dept_No) references Department(Dept_No));

create table Patient(

Pat_ID varchar(7) NOT NULL PRIMARY KEY,

Pat_Name varchar(20),

DOB date,

Gender char,

Contact number(10),

Address varchar(20));
Create table In_Patient (

Pat_ID varchar(7) NOT NULL,

Date_Of_Admission date ,

Bed_No number,

Start_Time timestamp,

End_Time timestamp,

constraint fkey2 foreign KEY(Pat_ID) references Patient(Pat_ID));

create table In_Patient_Prescription(

Pat_ID varchar(7),

Pres_ID varchar(7),

constraint fkey3 foreign KEY(Pat_ID) references Patient(Pat_ID));

create table Appointment (

App_ID varchar(7) NOT NULL PRIMARY KEY,

Pat_ID varchar(7),

Doc_ID varchar(5),

Nurse_ID varchar(5),

Consult_Room_No number,

Datep date,

Time timestamp,

constraint fkey4 foreign key(Pat_ID) references Patient(Pat_ID),

constraint fkey5 foreign key(Doc_ID) references Doctor(Doc_ID),

constraint fkey6 foreign key(Nurse_ID) references Staff(Staff_ID));


create table Prescription (

Pres_ID varchar(7) NOT NULL PRIMARY KEY,

App_ID varchar(7),

Datep date,

Time timestamp,

Diagnosis_Detail varchar(20),

constraint fkey7 foreign KEY(App_ID) references Appointment(App_ID));

create table Prescribed_Medicines (

Pres_ID varchar(7),

Medicine_Name varchar(20) NOT NULL ,

Dosage varchar(6),

Brand varchar(20),

constraint fkey9 foreign KEY(Pres_ID) references Prescription(Pres_ID));

create table Hospital_Bill (

Inv_No number(10) NOT NULL PRIMARY KEY,

Inv_Date date,

Pat_ID varchar(7),

Bill_Amount number(6),

Payment_Type varchar(12),

discount number,

constraint fkey10 foreign KEY(Pat_ID) references Patient(Pat_ID));

create table Lab_Tests (

Test_ID varchar(7) not null primary key,

Pat_ID varchar(7),
Datel Date,

Time timestamp,

constraint fkey11 foreign KEY(Pat_ID) references Patient(Pat_ID));

create table Test_Results (

Test_ID varchar(7) not null,

TT_ID varchar(7) not null,

Resultt varchar(7),

constraint fkey12 foreign KEY(Test_ID) references Lab_Tests(Test_ID));

create table Test_Types (TT_ID varchar(7) not null PRIMARY Key,

Description varchar(25),

Low_Value int,

High_Value int,

Test_Method varchar(10),

Technician varchar(5),

constraint fkey13 foreign KEY(Technician) references Staff(Staff_ID));

insert into Doctor values('D0001','Dr.Suresh','M','01-Jan-1975',

'Diabetes','MS',0123123,'Vellore','D001');

INSERT INTO Doctor VALUES('D0002','Dr.Mahesh','M','10-Feb-1977'

,'Diabetes','MBBS',0123651,'Vellore','D015');

INSERT INTO Doctor VALUES('D0003','Dr.Gajesh','M',

'01-Mar-1971','Cardiology','MS',0123324,'Vellore','D102');
INSERT INTO Doctor VALUES('D0004','Dr.Seeta','F','23-May-1971'

,'General_medicine','BDS',0123789,'Vellore','D013');

INSERT INTO Doctor VALUES('D0005','Dr.Maya','F'

,'31-Dec-1975','Ophthalmology','MDS',0123980,'Vellore','D014');

INSERT INTO Doctor VALUES('D0006','Dr.Hasaan','T','15-Mar-1979'

,'Neurology','MS',0123560,'Vellore','D016');

INSERT INTO Doctor VALUES('D0007','Dr.Gajraj','T','10-Jan-1973'

,'Diabetes','MBBS',0123780,'Vellore','D190');

Select * from Doctor;

insert into Department values('D001','Cardiology','G01',0,'D0003','11-Jan-2020');

insert into Department values('D015','Intensive_care_unit','101',1,'D0002','1-May-2020');

insert into Department values('D001','Gynacology','G01',0,'D000','6-June-2011');

insert into Department values('D013','Oncology','105',1,'D0004','8-Feb-2011');

insert into Department values('D014','Obstetrics_gynaecology','G17',0,'D0005','5-Oct-2016');

insert into Department values('D016','Neurology','302',3,'D0006','24-Mar-2015');

insert into Department values('D190','Diabetes','209',2,'D0007','1-Aug-2011');

select * from Department;

INSERT INTO Staff values('S0001','Salman','Nurse','Staff nurse','01-May-1975',

0918765432,'Vellore','D015');
INSERT INTO Staff values('S0002','Neha','lab technician','Senior technician','11-Jun-1981',

0918765433,'Vellore','D001');

INSERT INTO Staff values('S0003','Verman','lab technician','Technician','23-Apr-1972',

0918765434,'Vellore','D102');

INSERT INTO Staff values('S0004','Siva','Nurse','Head nurse','19-Jul-1976',

0918765435,'Vellore','D013');

INSERT INTO Staff values('S0005','Shilpa','Attender','Senior attender','03-Sep-1977',

0918765436,'Vellore','D014');

INSERT INTO Staff values('S0006','Mahima','Attender','Junior attender','12-Nov-1975',

0918765437,'Vellore','D016');

INSERT INTO Staff values('S0007','Greta','Cashier','Cashier maindesk','18-Jan-1975',

0918765438,'Vellore','D001');

INSERT INTO Staff values('S0008','Sally','Security','Security G1','17-Feb-1980',

0918765439,'Vellore','D001');

INSERT INTO Staff values('S0009','Abhilash','Nurse','Staff nurse','16-May-1970',

0918765430,'Vellore','D190');

INSERT INTO Staff values('S0010','Prathap','Nurse','Staff nurse','14-Nov-1974',

0918765431,'Vellore','D102');

select * from Staff;

INSERT INTO Patient values('PA00001','Mahesh Kumar','21-Jun-1974','M',9878987890,'Delhi');

INSERT INTO Patient values('PA00002','Shiv Prakash','11-Jan-1984','M',9878988890,'Vellore');

INSERT INTO Patient values('PA00003','Girija Roy','10-Dec-1972','F',9878987899,'Chennai');

INSERT INTO Patient values('PA00004','Sadhvi Gupta','13-Sep-1995','F',9878987891,'Delhi');

INSERT INTO Patient values('PA00005','Sri Harish','22-Jun-1991','T',9878937890,'Mumbai');

INSERT INTO Patient values('PA00006','Selvarajan','03-Jul-2001','T',9878985890,'Chennai');

INSERT INTO Patient values('PA00007','Mahitha Suri','10-May-1975','F',9878977890,'Chennai');

INSERT INTO Patient values('PA00008','Dibesh Kumar','27-Mar-1974','T',9878987860,'Chennai');


INSERT INTO Patient values('PA00009','Harish Sen','30-Nov-1984','M',9378987890,'Delhi');

INSERT INTO Patient values('PA00012','Suresh Kumar','14-Nov-1974','M',9899987890,'Vellore');

select * from Patient;

insert into In_Patient values('PA00001','01-Jan-2020',124,

'01-Jan-2020,06:12:12','01-Jan-2020,11:12:12 PM');

insert into In_Patient values('PA00002','11-Jan-2020',127,

'11-Jan-2020,07:00:00','13-Jan-2020,11:00:00 PM');

insert into In_Patient values('PA00003','21-Jan-2020',221,

'21-Jan-2020,06:00:00','05-Feb-2020,11:18:15 PM');

insert into In_Patient values('PA00004','10-Feb-2020',423,

'10-Feb-2020,06:12:12','11-Feb-2020,11:12:12 PM');

insert into In_Patient values('PA00005','12-Feb-2020',523,

'12-Feb-2020,07:12:12','12-Feb-2020,10:11:12 PM');

insert into In_Patient values('PA00006','26-Feb-2020',604,

'26-Feb-2020,06:12:12','26-Feb-2020,10:12:12 PM');

insert into In_Patient values('PA00007','01-May-2020',543,

'01-May-2020,05:10:12','04-May-2020,10:12:12 PM');

insert into In_Patient values('PA00008','11-May-2020',124,

'11-May-2020,06:00:00','12-May-2020,10:10:22 PM');

insert into In_Patient values('PA00009','21-May-2020',544,

'21-May-2020,06:12:12','21-May-2020,10:12:12 PM');

insert into In_Patient values('PA00012','01-Jun-2020',132,

'01-Jun-2020,06:12:12','01-Jun-2020,11:12:12 PM');

select * from In_Patient;


insert into In_Patient_Prescription values('PA00001','PR00001');

insert into In_Patient_Prescription values('PA00002','PR00002');

insert into In_Patient_Prescription values('PA00003','PR00003');

insert into In_Patient_Prescription values('PA00004','PR00004');

insert into In_Patient_Prescription values('PA00005','PR00005');

insert into In_Patient_Prescription values('PA00006','PR00006');

insert into In_Patient_Prescription values('PA00007','PR00007');

insert into In_Patient_Prescription values('PA00008','PR00008');

insert into In_Patient_Prescription values('PA00009','PR00009');

insert into In_Patient_Prescription values('PA00012','PR00012');

select * from In_Patient_Prescription;

insert into Appointment values('AP00001','PA00001','D0001',

'S0001',321,'1-Jan-2020','01-Jan-2020,06:30:00');

insert into Appointment values('AP00002','PA00002','D0002',

'S0002',324,'11-Jan-2020','11-Jan-2020,07:30:00');

insert into Appointment values('AP00003','PA00003','D0003',

'S0003',221,'21-Jan-2020','21-Jan-2020,06:30:00');

insert into Appointment values('AP00004','PA00004','D0004',

'S0004',121,'1-Jan-2020','10-Feb-2020,06:30:00');

insert into Appointment values('AP00005','PA00005','D0005',

'S0005',351,'1-Jan-2020','12-Feb-2020,07:30:00');

insert into Appointment values('AP00006','PA00006','D0006',

'S0006',329,'1-Jan-2020','26-Feb-2020,06:30:00');

insert into Appointment values('AP00007','PA00007','D0007',

'S0007',421,'1-Jan-2020','01-May-2020,05:30:00');
insert into Appointment values('AP00008','PA00008','D0001',

'S0008',300,'1-Jan-2020','11-May-2020,06:30:00');

insert into Appointment values('AP00009','PA00009','D0002',

'S0009',382,'1-Jan-2020','21-May-2020,06:30:00');

insert into Appointment values('AP00012','PA00012','D0003',

'S0010',112,'1-Jan-2020','01-Jun-2020,06:30:00');

select * from Appointment;

insert into Prescription values('PR00001','AP00001','01-Jan-2020','01-Jan-


2020,12:30:00','Hypertension');

insert into Prescription values('PR00002','AP00002','11-Jan-2020','11-Jan-


2020,07:50:00','Hyperlipidemia');

insert into Prescription values('PR00003','AP00003','21-Jan-2020','21-Jan-2020,07:30:00','Diabetes');

insert into Prescription values('PR00004','AP00004','10-Feb-2020','10-Feb-2020,07:00:00','Back pain');

insert into Prescription values('PR00005','AP00005','12-Feb-2020','12-Feb-2020,12:30:00','Anxiety');

insert into Prescription values('PR00006','AP00006','26-Feb-2020','26-Feb-2020,10:30:00','Obesity');

insert into Prescription values('PR00007','AP00007','01-May-2020','01-Jan-2020,12:30:00','Allergic


rhinitis');

insert into Prescription values('PR00008','AP00008','11-May-2020','11-May-2020,07:30:00','Reflux


esophagitis');

insert into Prescription values('PR00009','AP00009','21-May-2020','21-May-2020,07:30:00','Respiratory


problems');

insert into Prescription values('PR00012','AP00012','01-Jun-2020','01-Jun-


2020,08:30:00','Hypothyroidism');

select * from Prescription;

insert into Prescribed_Medicines values('PR00001','Synthrois','1-0-0','XYZ');

insert into Prescribed_Medicines values('PR00002','Crestoro','0-1-0','foo ');


insert into Prescribed_Medicines values('PR00003','Ventolinol HFA','1-0-1','XYZ');

insert into Prescribed_Medicines values('PR00004','Nexiumate','1-1-1','ABC');

insert into Prescribed_Medicines values('PR00005','Xanthitate','1-0-0','CDE');

insert into Prescribed_Medicines values('PR00006','Advair Diskusi','1-0-1','MNO');

insert into Prescribed_Medicines values('PR00007','Metatime 999VY','1-0-1','MNO');

insert into Prescribed_Medicines values('PR00008','Synthenol','1-1-0','IJK');

insert into Prescribed_Medicines values('PR00009','Gemerade','0-1-0','BDE');

insert into Prescribed_Medicines values('PR00012','Olvinol','0-1-0','QWRTY');

select * from Prescribed_Medicines;

insert into Hospital_Bill values('00001','01-Jan-2020',

'PA00001',100000,'debit card','20%');

insert into Hospital_Bill values('00002','11-Jan-2020',

'PA00002',160000,'debit card','10%');

insert into Hospital_Bill values('00003','01-Jan-2020',

'PA00001',80000,'cash','2%');

insert into Hospital_Bill values('00004','01-Jan-2020',

'PA00001','108000','debit card','5%');

insert into Hospital_Bill values('00005','01-Jan-2020',

'PA00001','150000','debit card','10%');

insert into Hospital_Bill values('00006','01-Jan-2020',

'PA00001','20000','credit card','5%');

insert into Hospital_Bill values('00007','01-Jan-2020',

'PA00001','200000','debit card','10%');

insert into Hospital_Bill values('00008','01-Jan-2020',

'PA00001','5000','cash','10%');
insert into Hospital_Bill values('00009','01-Jan-2020',

'PA00001','190000','credit card','10%');

insert into Hospital_Bill values('00012','01-Jan-2020',

'PA00001','100800','credit card','20%');

select * from Hospital_Bill;

insert into Lab_Tests values('TE00001','PA00001','01-Jan-2020','01-Jan-2020,11:00:00');

insert into Lab_Tests values('TE00002','PA00002','11-Jan-2020','11-Jan-2020,11:00:00');

insert into Lab_Tests values('TE00003','PA00003','21-Jan-2020','21-Jan-2020,11:00:00');

insert into Lab_Tests values('TE00004','PA00004','10-Feb-2020','10-Feb-2020,11:00:00');

insert into Lab_Tests values('TE00005','PA00005','12-Feb-2020','12-Feb-2020,11:00:00');

insert into Lab_Tests values('TE00006','PA00006','26-Feb-2020','26-Feb-2020,11:00:00');

insert into Lab_Tests values('TE00007','PA00007','01-May-2020','01-May-2020,11:00:00');

insert into Lab_Tests values('TE00008','PA00008','11-May-2020','11-May-2020,11:00:00');

insert into Lab_Tests values('TE00009','PA00009','21-May-2020','21-May-2020,11:00:00');

insert into Lab_Tests values('TE00012','PA00012','01-Jun-2020','01-Jun-2020,11:00:00');

select * from Lab_Tests;

insert into Test_Results values('TE00001','TT00001','positiv');

insert into Test_Results values('TE00002','TT00002','negativ');

insert into Test_Results values('TE00003','TT00003','positiv');

insert into Test_Results values('TE00004','TT00004','negativ');

insert into Test_Results values('TE00005','TT00005','positiv');

insert into Test_Results values('TE00006','TT00006','negativ');


insert into Test_Results values('TE00007','TT00007','positiv');

insert into Test_Results values('TE00008','TT00008','positiv');

insert into Test_Results values('TE00009','TT00009','positiv');

insert into Test_Results values('TE00012','TT00012','positiv');

select * from Test_Results;

insert into Test_Types values('TT00001','blood test',15,40,'Lab','S0001');

insert into Test_Types values('TT00002', 'urine test',35,40,'Lab','S0002');

insert into Test_Types values('TT00003','diabetic test',25,40,'Lab','S0003');

insert into Test_Types values('TT00004','blood test',15,45,'Lab','S0004');

insert into Test_Types values('TT00005','blood test',15,40,'Lab','S0005');

insert into Test_Types values('TT00006','urine test',35,40,'Lab','S0006');

insert into Test_Types values('TT00007','blood test',15,40,'Lab','S0007');

insert into Test_Types values('TT00008','urine test',35,40,'Lab','S0008');

insert into Test_Types values('TT00009','blood test',15,40,'Lab','S0009');

insert into Test_Types values('TT00012','blood test',15,40,'Lab','S0010');

select * from Test_Types;

You might also like