-
Notifications
You must be signed in to change notification settings - Fork 0
/
DDL.sql
329 lines (244 loc) · 6.81 KB
/
DDL.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
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
-- Table Save
CREATE TABLE IF NOT EXISTS save (
nome VARCHAR(30) NOT NULL,
PRIMARY KEY(nome));
-- Table Area
CREATE TABLE IF NOT EXISTS Area (
idArea INT NOT NULL,
descricao VARCHAR(50) NULL,
PRIMARY KEY (idArea));
-- Table Veiculo
CREATE TABLE IF NOT EXISTS Veiculo (
idVeiculo INT NOT NULL,
tipo VARCHAR(20) NULL,
velocidadeMax INT NULL,
idArea INT NOT NULL,
PRIMARY KEY (idVeiculo),
CONSTRAINT fk_Veiculo_Area1
FOREIGN KEY (idArea)
REFERENCES Area (idArea)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
-- Table NPC
CREATE TABLE IF NOT EXISTS NPC (
idNPC INT NOT NULL,
vida INT NULL,
tipo VARCHAR(30) NULL,
idArea INT NOT NULL,
PRIMARY KEY (idNPC),
CONSTRAINT fk_NPC_Area1
FOREIGN KEY (idArea)
REFERENCES Area (idArea)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
-- Table Jogador
CREATE TABLE IF NOT EXISTS Jogador (
idJogador INT GENERATED BY DEFAULT AS IDENTITY (START WITH 7) NOT NULL,
nome VARCHAR(30) NULL,
vida INT NULL,
dinheiro INT NULL,
nivelProcurado INT NULL,
xp INT NULL,
idVeiculo INT NOT NULL,
idNPC INT NOT NULL,
idArea INT NOT NULL,
idtarefa INT NOT NULL,
PRIMARY KEY (idJogador),
CONSTRAINT fk_Jogador_Veiculo1
FOREIGN KEY (idVeiculo)
REFERENCES Veiculo (idVeiculo)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT fk_Jogador_NPC1
FOREIGN KEY (idNPC)
REFERENCES NPC (idNPC)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
-- Table Item
CREATE TABLE IF NOT EXISTS Item (
idItem INT NOT NULL,
descricao VARCHAR(50) NULL,
usado INT NULL,
tipo VARCHAR(20) NULL,
PRIMARY KEY (idItem));
-- Table Loja
CREATE TABLE IF NOT EXISTS Loja (
nomeLoja VARCHAR(20) NOT NULL,
descricao VARCHAR(50) NULL,
estoque VARCHAR(20) NULL,
idItem INT NOT NULL,
idArea INT NOT NULL,
PRIMARY KEY (nomeLoja),
CONSTRAINT fk_Loja_Item1
FOREIGN KEY (idItem)
REFERENCES Item (idItem)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT fk_Loja_Area1
FOREIGN KEY (idArea)
REFERENCES Area (idArea)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
-- Table Arma
CREATE TABLE IF NOT EXISTS Arma (
idItem INT NOT NULL,
descricao VARCHAR(20) NULL,
preco INT NOT NULL,
tipo VARCHAR(20) NULL,
qtdDano INT NULL,
qtdBalas INT NULL,
PRIMARY KEY (idItem),
CONSTRAINT fk_Arma_Item1
FOREIGN KEY (idItem)
REFERENCES Item (idItem)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
-- Table Comida
CREATE TABLE IF NOT EXISTS Comida (
idItem INT NOT NULL,
nome VARCHAR(20) NULL,
descricao VARCHAR(50) NULL,
preco INT NULL,
tipo VARCHAR(20) NULL,
txRecuperacaoVida INT NULL,
PRIMARY KEY (idItem),
CONSTRAINT fk_Comida_Item1
FOREIGN KEY (idItem)
REFERENCES Item (idItem)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
-- Table Droga
CREATE TABLE IF NOT EXISTS Droga (
idItem INT NOT NULL,
descricao VARCHAR(50) NULL,
tipo VARCHAR(20) NULL,
vantagem VARCHAR(30) NULL,
desvantagem VARCHAR(30) NULL,
PRIMARY KEY (idItem),
CONSTRAINT fk_Droga_Item1
FOREIGN KEY (idItem)
REFERENCES Item (idItem)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
-- Table Inventario
CREATE TABLE IF NOT EXISTS Inventario (
idInventario INT GENERATED BY DEFAULT AS IDENTITY (START WITH 7) NOT NULL,
idJogador INT NOT NULL,
idItem INT NULL,
PRIMARY KEY (idInventario, idJogador),
CONSTRAINT fk_Inventario_Jogador
FOREIGN KEY (idJogador)
REFERENCES Jogador (idJogador)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT fk_Inventario_Item1
FOREIGN KEY (idItem)
REFERENCES Item (idItem)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
-- Table Membro de gangue
CREATE TABLE IF NOT EXISTS MembroDeGangue (
idNPC INT NOT NULL,
tipo VARCHAR(30) NULL,
PRIMARY KEY (idNPC),
CONSTRAINT fk_MembroDegangue_NPC1
FOREIGN KEY (idNPC)
REFERENCES NPC (idNPC)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
-- Table Membro de gangue aliada
CREATE TABLE IF NOT EXISTS MembroDeGangueAliada (
idNPC INT NOT NULL,
tipoAliado INT NULL,
vida INT NULL,
PRIMARY KEY (idNPC),
CONSTRAINT fk_MembroDeGangueAliada_MembroDeGangue1
FOREIGN KEY (idNPC)
REFERENCES MembroDeGangue(idNPC)
ON DELETE NO ACTION);
-- Table Membro de gangue inimiga
CREATE TABLE IF NOT EXISTS MembroDeGangueInimiga (
idNPC INT NOT NULL,
tipoInimigo INT NULL,
vida INT NULL,
PRIMARY KEY (idNPC),
CONSTRAINT fk_MembroDeGangueInimiga_MembroDeGangue1
FOREIGN KEY (idNPC)
REFERENCES MembroDeGangue (idNPC)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
-- Table Policial
CREATE TABLE IF NOT EXISTS Policial (
idNPC INT NOT NULL,
vida INT NULL,
danoPolicial INT NULL,
tipoPolicial VARCHAR(10) NULL,
PRIMARY KEY (idNPC),
CONSTRAINT fk_Policial_NPC1
FOREIGN KEY (idNPC)
REFERENCES NPC (idNPC)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
-- Table Tarefas
CREATE TABLE IF NOT EXISTS Tarefas (
nomeTarefa VARCHAR(30) NOT NULL,
dificuldade INT NULL,
objetivo VARCHAR(50) NULL,
xp INT NULL,
idNPC INT NOT NULL,
NumTarefa INT NOT NULL UNIQUE,
PRIMARY KEY (nomeTarefa,idNPC),
CONSTRAINT fk_Tarefas_MembroDeGangueAliada1
FOREIGN KEY (idNPC)
REFERENCES MembroDeGangueAliada (idNPC)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
-- Table Mapa
CREATE TABLE IF NOT EXISTS Mapa (
idMapa INT NOT NULL,
descricao VARCHAR(50) NULL,
PRIMARY KEY (idMapa));
-- Table Jogador_has_Tarefas
CREATE TABLE IF NOT EXISTS Jogador_has_Tarefas (
Jogador_idJogador INT NOT NULL,
Tarefas_nomeTarefa VARCHAR(30) NOT NULL,
Tarefas_idNPC INT NOT NULL,
PRIMARY KEY (Jogador_idJogador, Tarefas_nomeTarefa, Tarefas_idNPC),
CONSTRAINT fk_Jogador_has_Tarefas_Jogador1
FOREIGN KEY (Jogador_idJogador)
REFERENCES Jogador (idJogador)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT fk_Jogador_has_Tarefas_Tarefas1
FOREIGN KEY (Tarefas_nomeTarefa , Tarefas_idNPC)
REFERENCES Tarefas (nomeTarefa , idNPC)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
CREATE TABLE IF NOT EXISTS AreaCArea (
idA1 INT NOT NULL,
idA2 INT NOT NULL,
PRIMARY KEY (idA1, idA2),
CONSTRAINT fk_AreaParaArea
FOREIGN KEY (idA1)
REFERENCES Area (idArea)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT fk_AreaParaArea2
FOREIGN KEY (idA2)
REFERENCES Area (idArea)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
CREATE TABLE IF NOT EXISTS Loja_possui_Item (
nomeLoja VARCHAR(50) NOT NULL,
idItem INT NOT NULL,
PRIMARY KEY (nomeLoja, idItem),
CONSTRAINT fk_Loja_possui_Item_Loja1
FOREIGN KEY (nomeLoja)
REFERENCES Loja (nomeLoja)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT fk_Loja_possui_Item_Item1
FOREIGN KEY (idItem)
REFERENCES Item (idItem)
ON DELETE NO ACTION
ON UPDATE NO ACTION);