-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateTables.sql
87 lines (77 loc) · 2.32 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
-- CREATING TABLES
-- Foreign key dependant tables here
DROP TABLE IF EXISTS Address;
DROP TABLE IF EXISTS DoctorSpec;
DROP TABLE IF EXISTS Review;
DROP TABLE IF EXISTS SocialNetwork;
DROP TABLE IF EXISTS Specialization;
DROP TABLE IF EXISTS Doctor;
DROP TABLE IF EXISTS Patient;
DROP TABLE IF EXISTS User;
CREATE TABLE User(
username VARCHAR(100), -- user alias, either docAlias or patAlias
salt VARCHAR(64),
hash VARCHAR(64),
role CHAR(1), -- 0 for doctor, 1 for patient
PRIMARY KEY(username)
);
CREATE TABLE Doctor(
docAlias VARCHAR(100),
firstName VARCHAR(100),
lastName VARCHAR(100),
gender VARCHAR(20),
docEmail VARCHAR(100),
yearLicensed INTEGER,
PRIMARY KEY(docAlias),
FOREIGN KEY(docAlias) REFERENCES User(username)
);
CREATE TABLE Address(
id INTEGER NOT NULL AUTO_INCREMENT,
docAlias VARCHAR(100),
address VARCHAR(100),
city VARCHAR(100),
province VARCHAR(100),
postalCode VARCHAR(100),
PRIMARY KEY(id),
FOREIGN KEY(docAlias) REFERENCES Doctor(docAlias)
);
CREATE TABLE Specialization(
specId INTEGER NOT NULL AUTO_INCREMENT,
field VARCHAR(100),
PRIMARY KEY(specId)
);
CREATE TABLE DoctorSpec(
docAlias VARCHAR(100),
specId INTEGER,
PRIMARY KEY (docAlias, specId),
FOREIGN KEY (docAlias) REFERENCES Doctor(docAlias),
FOREIGN KEY (specId) REFERENCES Specialization(specId)
);
CREATE TABLE Patient(
patAlias VARCHAR(100),
firstName VARCHAR(100),
lastName VARCHAR(100),
city VARCHAR(100),
province VARCHAR(100),
patEmail VARCHAR(100),
PRIMARY KEY(patAlias),
FOREIGN KEY(patAlias) REFERENCES User(username)
);
CREATE TABLE Review(
reviewId INTEGER NOT NULL AUTO_INCREMENT,
submitDate DATETIME,
patAlias VARCHAR(100),
docAlias VARCHAR(100),
rating FLOAT NOT NULL,
comments VARCHAR(1000),
PRIMARY KEY (reviewId),
FOREIGN KEY (patAlias) REFERENCES Patient(patAlias),
FOREIGN KEY (docAlias) REFERENCES Doctor(docAlias)
);
CREATE TABLE SocialNetwork(
patAlias VARCHAR(100),
friendAlias VARCHAR(100),
PRIMARY KEY(patAlias, friendAlias),
FOREIGN KEY (patAlias) REFERENCES Patient(patAlias),
FOREIGN KEY (friendAlias) REFERENCES Patient(patAlias)
);