forked from esjoo/SchedLab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_database.txt
90 lines (72 loc) · 1.93 KB
/
create_database.txt
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
CREATE TABLE Users (
UserNum int NOT NULL PRIMARY KEY AUTO_INCREMENT,
Lab varchar(255),
Pword varchar(255) NOT NULL,
Name varchar(255) NOT NULL,
Manage_Num int
);
CREATE TABLE Make (
UserNum int,
ProtocolNum int,
Time time
);
CREATE TABLE Include (
ProtocolNum int,
SupID int,
Dosage varchar(255)
);
CREATE TABLE Consume (
ExpeNum int,
SupID int,
Amount float
);
CREATE TABLE Protocol (
ProtID int NOT NULL PRIMARY KEY AUTO_INCREMENT,
ProtName varchar(255),
Method text,
AllEquipment text,
AllReagent text,
UserNum int
);
CREATE TABLE Experiment (
ExpeNum int NOT NULL PRIMARY KEY AUTO_INCREMENT,
Result text,
ProtID int
);
CREATE TABLE Supplement (
SupID int NOT NULL PRIMARY KEY AUTO_INCREMENT,
SupName varchar(255),
Price float NOT NULL,
Stock int
);
CREATE TABLE Do (
UserNum int,
ExpeNum int,
Time_incalendar datetime
);
CREATE TABLE Buy (
UserNum int,
SupID int,
Amount int NOT NULL
);
ALTER TABLE Protocol
ADD FOREIGN KEY (UserNum) REFERENCES Users(UserNum);
ALTER TABLE Experiment
ADD FOREIGN KEY (ProtID) REFERENCES Protocol(ProtID);
ALTER TABLE Do
ADD (FOREIGN KEY (UserNum) REFERENCES Users(UserNum),
FOREIGN KEY (ExpeNum) REFERENCES Experiment(ExpeNum));
ALTER TABLE Buy
ADD (FOREIGN KEY (UserNum) REFERENCES Users(UserNum),
FOREIGN KEY (SupID) REFERENCES Supplement(SupID));
ALTER TABLE Users
ADD FOREIGN KEY (Manage_Num) REFERENCES Users(UserNum);
ALTER TABLE Make
ADD (FOREIGN KEY (UserNum) REFERENCES Users(UserNum),
FOREIGN KEY (ProtocolNum) REFERENCES Protocol(ProtID));
ALTER TABLE Include
ADD (FOREIGN KEY (ProtocolNum) REFERENCES Protocol(ProtID),
FOREIGN KEY (SupID) REFERENCES Supplement(SupID));
ALTER TABLE Consume
ADD (FOREIGN KEY (ExpeNum) REFERENCES Experiment(ExpeNum),
FOREIGN KEY (SupID) REFERENCES Supplement(SupID));