CREATE TABLE AllProducts Product_ID int NOT NULL Type varchar 20 NOT N

  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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
CREATE TABLE AllProducts (
Product_ID int NOT NULL,
Type varchar(20) NOT NULL,
PRIMARY KEY (Product_ID)
);
CREATE TABLE CPU (
CPU_ID int NOT NULL AUTO_INCREMENT,
Producer varchar(20) NOT NULL,
Model varchar(30) NOT NULL UNIQUE KEY,
Socket varchar(20) NOT NULL,
NCores int NOT NULL,
Frequency float NOT NULL,
SupMem varchar(20) NOT NULL,
FrequencySupMem float NOT NULL,
Price int NOT NULL,
PRIMARY KEY (CPU_ID),
FOREIGN KEY (CPU_ID) REFERENCES AllProducts(Product_ID)
ON DELETE CASCADE
ON UPDATE CASCADE
)AUTO_INCREMENT=1;
CREATE TABLE MBoards (
MBoard_ID int NOT NULL AUTO_INCREMENT,
Producer varchar(20) NOT NULL,
Model varchar(30) NOT NULL UNIQUE KEY,
Socket varchar(20) NOT NULL,
Chipset varchar(20) NOT NULL,
RAM varchar(50) NOT NULL,
ExpSlots varchar(50) NOT NULL,
VideoCon varchar(30) NOT NULL DEFAULT '',
DevInterfaces varchar(30) NOT NULL,
FormFactor varchar(20) NOT NULL,
Price int NOT NULL,
PRIMARY KEY (MBoard_ID),
FOREIGN KEY (MBoard_ID) REFERENCES AllProducts(Product_ID)
ON DELETE CASCADE
ON UPDATE CASCADE
)AUTO_INCREMENT=1001;
CREATE TABLE RAM (
RAM_ID int NOT NULL AUTO_INCREMENT,
Producer varchar(20) NOT NULL,
Model varchar(30) NOT NULL UNIQUE KEY,
Type varchar(20) NOT NULL,
Size int NOT NULL,
Frequency int NOT NULL,
Price int NOT NULL,
PRIMARY KEY (RAM_ID),
FOREIGN KEY (RAM_ID) REFERENCES AllProducts(Product_ID)
ON DELETE CASCADE
ON UPDATE CASCADE
)AUTO_INCREMENT=2001;
CREATE TABLE ROM (
ROM_ID int NOT NULL AUTO_INCREMENT,
Producer varchar(20) NOT NULL,
Model varchar(30) NOT NULL UNIQUE KEY,
Type varchar(20) NOT NULL,
ConType varchar(20) NOT NULL,
Capacity int NOT NULL,
Interface varchar(20) NOT NULL,
FormFactor varchar(20) NOT NULL,
Price int NOT NULL,
PRIMARY KEY (ROM_ID),
FOREIGN KEY (ROM_ID) REFERENCES AllProducts(Product_ID)
ON DELETE CASCADE
ON UPDATE CASCADE
)AUTO_INCREMENT=3001;
CREATE TABLE Video(
Video_ID int NOT NULL AUTO_INCREMENT,
Producer varchar(20) NOT NULL,
Model varchar(20) NOT NULL UNIQUE KEY,
GPU varchar(20) NOT NULL,
MemSize int NOT NULL,
MaxResolution varchar(30) NOT NULL,
Interface varchar(30) NOT NULL,
Connectors varchar(30) NOT NULL,
Price int NOT NULL,
PRIMARY KEY (Video_ID),
FOREIGN KEY (Video_ID) REFERENCES AllProducts(Product_ID)
ON DELETE CASCADE
ON UPDATE CASCADE
)AUTO_INCREMENT=4001;
CREATE TABLE OptDrives (
OptDrive_ID int NOT NULL AUTO_INCREMENT,
Producer varchar(20) NOT NULL,
Model varchar(30) NOT NULL UNIQUE KEY,
Type varchar(20) NOT NULL,
ConType varchar(20) NOT NULL,
Interface varchar(20) NOT NULL,
RecSpeed varchar(30) NOT NULL,
ReadSpeed varchar(30) NOT NULL,
Price int NOT NULL,
PRIMARY KEY (OptDrive_ID),
FOREIGN KEY (OptDrive_ID) REFERENCES AllProducts(Product_ID)
ON DELETE CASCADE
ON UPDATE CASCADE
)AUTO_INCREMENT=5001;
CREATE TABLE Power (
Power_ID int NOT NULL AUTO_INCREMENT,
Producer varchar(20) NOT NULL,
Model varchar(30) NOT NULL UNIQUE KEY,
Capacity int NOT NULL,
VentSize int NOT NULL,
Price int NOT NULL,
PRIMARY KEY (Power_ID),
FOREIGN KEY (Power_ID) REFERENCES AllProducts(Product_ID)
ON DELETE CASCADE
ON UPDATE CASCADE
)AUTO_INCREMENT=6001;
CREATE TABLE Coolers(
Cooler_ID int NOT NULL AUTO_INCREMENT,
Producer varchar(20) NOT NULL,
Model varchar(30) NOT NULL UNIQUE KEY,
Type varchar(20) NOT NULL,
BearingType varchar(20) NOT NULL,
VentSize int NOT NULL,
ConCPU varchar(50) NOT NULL,
Price int NOT NULL,
PRIMARY KEY (Cooler_ID),
FOREIGN KEY (Cooler_ID) REFERENCES AllProducts(Product_ID)
ON DELETE CASCADE
ON UPDATE CASCADE
) AUTO_INCREMENT=7001;
CREATE TABLE Cases(
Case_ID int NOT NULL AUTO_INCREMENT,
Producer varchar(20) NOT NULL,
Model varchar(30) NOT NULL UNIQUE KEY,
Type varchar(30) NOT NULL UNIQUE KEY,
Color varchar(20) NOT NULL,
FormFactor varchar(20) NOT NULL,
Price int NOT NULL,
PRIMARY KEY (Case_ID),
FOREIGN KEY (Case_ID) REFERENCES AllProducts(Product_ID)
ON DELETE CASCADE
ON UPDATE CASCADE
)AUTO_INCREMENT=8001;
CREATE TABLE Users (
User_ID int NOT NULL AUTO_INCREMENT,
Login VARCHAR(60) NOT NULL UNIQUE KEY,
Password VARCHAR(255) NOT NULL,
Mail VARCHAR(255) NOT NULL UNIQUE KEY,
Name varchar(30) NOT NULL,
Surname varchar(50) NOT NULL,
Telephone varchar(30) NOT NULL DEFAULT = '',
City varchar(30) NOT NULL DEFAULT = '',
PRIMARY KEY (User_ID)
);
CREATE TABLE Orders (
Order_ID int NOT NULL AUTO_INCREMENT,
User_ID int NOT NULL,
Amount int NOT NULL,
PRIMARY KEY (Order_ID),
FOREIGN KEY (User_ID) REFERENCES Users(User_ID)
ON DELETE CASCADE
ON UPDATE CASCADE
);
CREATE TABLE Computers (
Comp_ID int NOT NULL AUTO_INCREMENT,
Model varchar(30) NOT NULL UNIQUE KEY,
CPU_ID int NOT NULL,
MBoard_ID int NOT NULL,
RAM_ID int NOT NULL,
ROM_ID int NOT NULL,
OptDrive_ID int Not NULL,
Video_ID int NOT NULL,
Power_ID int NOT NULL,
Cooler_ID int NOT NULL,
Case_ID int NOT NULL,
Price int NOT NULL,
PRIMARY KEY (Comp_ID),
FOREIGN KEY (CPU_ID) REFERENCES CPU(CPU_ID)
ON DELETE CASCADE
ON UPDATE CASCADE,
FOREIGN KEY (MBoard_ID) REFERENCES MBoards(MBoard_ID)
ON DELETE CASCADE
ON UPDATE CASCADE,
FOREIGN KEY (RAM_ID) REFERENCES RAM(RAM_ID)
ON DELETE CASCADE
ON UPDATE CASCADE,
FOREIGN KEY (ROM_ID) REFERENCES ROM(ROM_ID)
ON DELETE CASCADE
ON UPDATE CASCADE,
FOREIGN KEY (OptDrive_ID) REFERENCES OptDrives(OptDrive_ID)
ON DELETE CASCADE
ON UPDATE CASCADE,
FOREIGN KEY (Video_ID) REFERENCES Video(Video_ID)
ON DELETE CASCADE
ON UPDATE CASCADE,
FOREIGN KEY (Power_ID) REFERENCES Power(Power_ID)
ON DELETE CASCADE
ON UPDATE CASCADE,
FOREIGN KEY (Cooler_ID) REFERENCES Coolers(Cooler_ID)
ON DELETE CASCADE
ON UPDATE CASCADE,
FOREIGN KEY (Case_ID) REFERENCES Cases(Case_ID)
ON DELETE CASCADE
ON UPDATE CASCADE,
FOREIGN KEY (Comp_ID) REFERENCES AllProducts(Product_ID)
ON DELETE CASCADE
ON UPDATE CASCADE
)AUTO_INCREMENT=9001;
CREATE TABLE OrderItems (
Order_ID int NOT NULL,
Product_ID int NOT NULL,
Qty int NOT NULL,
FOREIGN KEY (Order_ID) REFERENCES Orders(Order_ID)
ON DELETE CASCADE
ON UPDATE CASCADE,
FOREIGN KEY (Product_ID) REFERENCES AllProducts(Product_ID)
ON DELETE CASCADE
ON UPDATE CASCADE
);