-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateTables.sql
116 lines (98 loc) · 2.71 KB
/
CreateTables.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
-- USE COVIDVACCINE;
CREATE TABLE TOWN_TABLE
(
TNAME VARCHAR(50) NOT NULL PRIMARY KEY ,
POPULATION BIGINT NOT NULL ,
COUNTRY VARCHAR(50) NOT NULL
);
CREATE TABLE INFO_TABLE
(
VIRUSNAME VARCHAR(50) NOT NULL PRIMARY KEY ,
UNITPRICE BIGINT NOT NULL
);
CREATE TABLE SIDEEFFECT_TABLE
(
VIRUSNAME VARCHAR(50) NOT NULL PRIMARY KEY,
SIDEEFFECT VARCHAR(50) NOT NULL PRIMARY KEY,
CONSTRAINT fk_SIid FOREIGN KEY(VIRUSNAME)
REFERENCES INFO_TABLE(VIRUSNAME)
);
CREATE TABLE SUPPLIER_TABLE
(
SLICENSE BIGINT NOT NULL PRIMARY KEY ,
SNAME VARCHAR(50) NOT NULL,
ADDRESS VARCHAR(50) NOT NULL ,
EMAIL VARCHAR(50) NOT NULL ,
PHONENUMBER BIGINT NOT NULL
);
CREATE TABLE HMO_TABLE
(
HMOLICENSE BIGINT NOT NULL PRIMARY KEY ,
HMONAME VARCHAR(50) NOT NULL ,
ADDRESS VARCHAR(50) NOT NULL ,
PHONENUMBER BIGINT NOT NULL ,
STOCK BIGINT ,
EMAIL VARCHAR(50) NOT NULL ,
TOWN VARCHAR(50) NOT NULL ,
CONSTRAINT fk_HTid FOREIGN KEY(TOWN)
REFERENCES TOWN_TABLE(TNAME)
);
CREATE TABLE ORDER_TABLE
(
OID BIGINT NOT NULL AUTO_INCREMENT ,
STATUS VARCHAR(50) NOT NULL CHECK
(STATUS IN ('SHIPPED' , 'IN PROCESS' , 'DELIVERED')),
QUANTITY BIGINT NOT NULL ,
ESTIMATEDDATE DATETIME NOT NULL ,
DESTINATION VARCHAR(50) NOT NULL ,
HMOLICENSE BIGINT NOT NULL ,
SLICENSE BIGINT NOT NULL ,
PRIMARY KEY (OID , HMOLICENSE) ,
CONSTRAINT fk_OSid FOREIGN KEY(SLICENSE)
REFERENCES SUPPLIER_TABLE(SLICENSE),
CONSTRAINT fk_OHid FOREIGN KEY(HMOLICENSE)
REFERENCES HMO_TABLE(HMOLICENSE)
ON DELETE CASCADE
);
CREATE TABLE VACCINE_TABLE
(
SERIALNUMBER BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
EXPIRATIONDATE DATE NOT NULL ,
VIRUSNAME VARCHAR(50) NOT NULL ,
MAKERID BIGINT NOT NULL ,
AVAILABLEINHMOID BIGINT NOT NULL,
CONSTRAINT fk_VHid FOREIGN KEY(AVAILABLEINHMOID)
REFERENCES HMO_TABLE(HMOLICENSE),
CONSTRAINT fk_VSid FOREIGN KEY(MAKERID)
REFERENCES SUPPLIER_TABLE(SLICENSE),
CONSTRAINT fk_VIid FOREIGN KEY(VIRUSNAME)
REFERENCES INFO_TABLE(VIRUSNAME)
);
CREATE TABLE PERSON_TABLE
(
PID BIGINT NOT NULL PRIMARY KEY ,
FNAME VARCHAR(50) NOT NULL ,
LNAME VARCHAR(50) NOT NULL ,
DATEOFBIRTH DATE NOT NULL ,
PHONENUM BIGINT NOT NULL ,
EMAIL VARCHAR(50) ,
LIVEIN VARCHAR(50) NOT NULL ,
HMOTREATEDINID BIGINT NOT NULL ,
CONSTRAINT fk_PTid FOREIGN KEY(LIVEIN)
REFERENCES TOWN_TABLE(TNAME) ,
CONSTRAINT fk_PHid FOREIGN KEY(HMOTREATEDINID)
REFERENCES HMO_TABLE(HMOLICENSE)
);
CREATE TABLE MEDICALRECORD_TABLE
(
FILEID VARCHAR(50) NOT NULL PRIMARY KEY ,
PID BIGINT NOT NULL UNIQUE,
BLOODTYPE VARCHAR(50) NOT NULL ,
STOREDINHMOID BIGINT NOT NULL ,
VACCINESTATUS VARCHAR(50) NOT NULL
CHECK (VACCINESTATUS IN ('VACCINATED' , 'NOT VACCINATED')) ,
CONSTRAINT fk_MPid FOREIGN KEY(PID)
REFERENCES PERSON_TABLE(PID) ,
CONSTRAINT fk_MHid FOREIGN KEY(STOREDINHMOID)
REFERENCES HMO_TABLE(HMOLICENSE)
);