-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate.sql
36 lines (24 loc) · 1.49 KB
/
create.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
drop table distance;
drop table blood_br;
drop table branch;
drop table organization;
drop table blood;
drop table donor;
drop table dummy;
create table donor (d_id varchar(5) primary key , name varchar(20), dob date, gender
varchar(6), b_group varchar(5), phone varchar(12), weight float);
create table blood (b_id varchar(5) primary key, hgb_level float, wbc float, rbc float, platelet float, date date, d_id varchar(5) unique,
foreign key (d_id) references donor(d_id) on delete cascade on update cascade);
create table organization( o_id varchar(5) primary key, org_name varchar(30), no_of_br int);
create table branch(o_id varchar(5), br_id varchar(5), address varchar(35), br_phone
varchar(12), foreign key (o_id) references organization(o_id) on delete cascade on update
cascade, primary key(br_id, o_id));
create table blood_br(b_id varchar(5) primary key, o_id varchar(5), br_id varchar(5), foreign
key (o_id,br_id) references branch (o_id,br_id) on delete cascade on update cascade,foreign key
(b_id) references blood(b_id) on delete cascade on update cascade);
create table distance(o_id varchar(5), br_id varchar(5), h_id varchar(5), dist float, foreign key
(o_id, br_id) references branch(o_id, br_id) on delete cascade on update cascade, primary
key(o_id, br_id, h_id));
create table dummy (name varchar(10));
create trigger forDate after insert on dummy for each row begin call delDate(); end;//
create procedure delDate() begin delete from blood where (select datediff(curdate(),date)) > 46; end;//