DBMS Project
DBMS Project
DBMS Project
Submitted By:
BE Third Year, ENC5
Pratham Gupta (102015095)
Submitted To: -
Mrs. Satnam Kaur
INDEX
1
Sr. No. Contents Page No.
1 Problem Statement 3
2 ER Diagram 4
3 ER to Table 8
4 Normalization 15
5 SQL/PLSQL 28
2
Problem Statement
Patients require blood to survive operations, cancer treatments, chronic
diseases, and traumatic traumas. This lifesaving care begins with a
thoughtful contribution from one individual. The demand for blood is
never-ending.
In 2016, 10.9 million donations were recorded, whereas in 2020, 12.7
million donations were reported, little less than expected but still
sufficient despite the epidemic. As engineers, we have attempted to
make the process of maintaining all records easier.
We're building a database that will keep all of the information regarding
donors, recipients, blood inventories, organisations, and camps which
can be used to retreive, update, and collect data.
The main benefit of having a database for blood bank administration is
the quick and easy retrieval of information. Manual procedures can be
eliminated. Databases help you save time and enhance the quality and
consistency of your information.
3
ER Diagram
ER Model stands for Entity Relationship Model is a high-level
conceptual data model diagram. ER model helps to systematically
analyse data requirements to produce a well-designed database. The ER
Model represents real-world entities and the relationships between
them. Creating an ER Model in DBMS is considered as a best practice
before implementing your database.
The ER Entity Relation diagram is a visual representation of all the
entities and their attributes with their relationships.
The ER diagram made for our project consists of two entities with their
18 attributes describing how the various processes and entities are
related in our database.
4
ER-DIAGRAM DESCRIPTION
ENTITIES AND ATTRIBUTES:
5
State: It is a single valued field that stores a valid state name as a part of
their address.
Address: It is a single valued field that stores local/ regional address of
the user.
City: It is a single valued field that stores valid city name for the
organization.
Contact ID: It is a field which identifies the donor and receiver
individually.
OID: Organization ID a single valued key to uniquely identify an
organization.
6
Phone: It is an attribute storing the phone no. of recipients and is of type
number.
7
Venue: It denotes the location of the camp organized and stores it in
varchar format.
Info: It stores some miscellaneous information about the camp in
varchar format.
8
ER to Table
Creating tables
create table donor( uid int, name varchar(20), phone_no bigint(10), email
varchar(20), DOB date, pwd varchar(30), blood_group varchar(5), primary key
(uid) );
9
varchar(20),
blood_group(5)
);
10
create table organisation( oid int,
contact_id bigint(10),
email varchar(20), state
varchar(20), address
varchar(50), city
varchar(20), primary key
(oid) );
create table donation( certificate_id bigint(4), uid int primary key, name
varchar(30), phone_no bigint(10), email varchar(20), DOB date, pwd varchar(30),
blood_group varchar(5),
oid1 int,
foreign key (oid1) references organisation(oid) );
11
create table organizes(
oid1 int, cid int primary
key, date1 date, timer
time, info varchar(30),
venue varchar(30),
name varchar(30),
foreign key (oid1) references organisation(oid) );
12
create table inventory( oid1 int,
bloodid int primary key,
btype varchar(5), date1 date, amount int foreign
key (oid1) references organisation(oid));
13
btype varchar(5), date1
date, amount int
);
14
15
Normalization
1NF/First Normal Form
A table is said to be in first normal form id there are no multiple values
for a cell in a table. The tables used in our project such as
DONOR, DONATIONS and so on are in first normal form as they do
not accept multiple values of an attribute per tuple.
The fields such as Email, Phone number can have multiple values per
tuple so either multiple columns such as phone1, phone2 were to be
provided or decomposition was to be done which was preferred.
2NF/Second Normal Form
This normal form states that partial functional dependencies cannot
exist. To keep tables in second normal form, primary keys assigned have
only one attribute in case of each table.
We have primary keys such as UID, OID etc which consist of only one
attribute which solves the problem of partial functional dependency.
16
Inserting Values
insert into donor values(0001,'Ram',9898989898,'1@gmailcom','2001-01-01','xyzabc','b+');
17
donor values(0020,'rewaa',9898389898,'10@gmailcom','2001-01-12','xyzfbc','B+'); insert into
values(0029,'Bannoa',9898969898,'19@gmailcom','2001-01-21','xyzaic','B-');
RECIPIENT:
18
recipient values(0009,'kmid',9898989898,'9@gmailcom','C+'); insert into
19
REQUEST:
20
values(0021,0021); insert into request
values(0029,0029);
ORGANISATION:
ROAD','Bhatinda');
21
DONATION:
22
insert into donation values(21,0022,'Amaa',9898949898,'2@gmailcom','2001-01-
02','xyzfbc','A+',1114);
ORGANIZES:
23
insert into organizes values(1114,50,'2022-04-07','13:00:00','quarterly blood donation
camp','aadarsh nagar','camp4');
INVENTORY:
24
insert into inventory values(1114,107,'b-','2021-05-01',2); insert
inventory values(1111,128,'o-','2021-05-09',1);
25
BLOOD:
26
values(119,'AB+','2021-05-01',1); insert into blood
values(124,'o+','2021-05-13',1);
27
recipient1 values('O+',1014,'14@gmail.com','Raman',6565651565,113); insert into
28
SQL/PLSQL
QUERIES
1.FIND
THE NAME OF DONOR FOR RECIPENT WHO RECEIVED BLOOD
FROM UID 10!
select name from donor where uid in ( select uid1 from request where uid2 in ( select uid from
recipient where uid=10))
29
3.DISPLAY THE NAMES AND CONTACT OF THE PEOPLE WHO HAVE
DONATED BLOOD IN PATIALA CITY.
SELECT name, phone_no from donation where oid1 in (select oid from organisation where
city="Patiala");
select count(*) from donation where oid1 in (select oid from organisation where
city="Amritsar")
30
6.UPDATE PHONE NUMBER OF DONOR WITH ID 0001:
select name, phone_no from donor where uid=0001; update
donor set phone_no = 9818814747 where uid=0001; select
name, phone_no from donor where uid=0001;
31
8.DISPLAY TOTAL AMOUNT OF B+ BLOOD COLLECTRRD FROM
PATIALA CITY BY ANY ORGANISATION/CAMP.
32
PLSQL
1.Write a code to check whether a given blood sample is in stock and if yes
display to user else raise an exception.
declare ab blood.btype%type; begin select btype
into ab from blood where bloodid=110;
dbms_output.put_line('AMPLE FOUND IN STOCK AND THE
REQUESTED BLOOD SAMPLE IS '||ab); exception when too_many_rows
then dbms_output.put_line('query returned more than one record'); end;
33
2.WRITE A CODE TO CHECK IF THE USER HAS ENTERED VALUES
ACCORDING TO THE CORRECT DATA TYPE
exception
when invalid_number then
dbms_output.put_line(' Conversion of string to number failed ');
end;
USING CURSOR:
3.UPDATE THE DONOR DATA BUT FIRST CHECK IF THE DONOR
EXISTES ELSE RAISE EXCEPTION
34
declare
total_rows number(2);
begin
update donor
set phone_no = 987456321124 where usid = 0014;
if sql%notfound then dbms_output.put_line(' NO SUCH DONOR FOUND ');
elsif sql%found then total_rows:=sql%rowcount;
dbms_output.put_line('rows affected
'||total_rows); end if; end;
4.Write a procedure to return the people with a particular blood type and
names starting from 'k' and 'r'
create or replace procedure blood_filter(b in varchar,n in varchar) is
bg donor.blood_group%type;
np donor.name%type; id
donor.usid%type; cursor cf is
select usid, name, blood_group from donor where blood_group==b and n LIKE 'r%' or
n LIKE 'R%' or n LIKE 'k%' or n LIKE 'K%'; begin open cf; loop fetch cf into id,np,bg;
exit when cf%notfound; dbms_output.put_line(np|| ' with id = ' ||
id || ' has blood group ' || bg); end loop; close cf; exception
when no_data_found then
dbms_output.put_line('Sorry no such products exist'); end;
35
5.Write a procedure to check if there is an organisation in the given city else raise
an exception
6.Write a procedure to check if there exists a certificate ID and its not duplicate
create or replace procedure certification(i in integer) is
c_id integer; begin
select certificate_id into c_id from donation where certificate_id=i; exception
when no_data_found then
dbms_output.put_line('Sorry no such certificate exists !!');
36
when too_many_rows then
dbms_output.put_line('Duplicate certificates exist'); end;
37
create or replace trigger count_donor before insert
dbms_output.put_line(count1); end;
38