· 8 years ago · Nov 21, 2017, 03:54 AM
1drop table if exists ALPLI;
2
3drop table if exists ARTGRU;
4
5drop table if exists ARTYALB;
6
7drop table if exists ARTYPLI;
8
9drop table if exists Albumy;
10
11drop table if exists Artyści;
12
13drop table if exists CZUŻY;
14
15drop table if exists Czaty;
16
17drop table if exists EVEART;
18
19drop table if exists EVEGRU;
20
21drop table if exists EVETAG;
22
23drop table if exists EVEUŻY;
24
25drop table if exists Eventy;
26
27drop table if exists GRUTAG;
28
29drop table if exists GRUUŻY;
30
31drop table if exists Gadżety;
32
33drop table if exists Gatunki;
34
35drop table if exists Grupy;
36
37drop table if exists PLAYTAG;
38
39drop table if exists PLIPÅY;
40
41drop table if exists Playlisty;
42
43drop table if exists Pliki;
44
45drop table if exists Posty;
46
47drop table if exists Płyty;
48
49drop table if exists Sklepy;
50
51drop table if exists Tagi;
52
53drop table if exists UŻYART;
54
55drop table if exists UŻYGRU;
56
57drop table if exists UŻYUŻY;
58
59drop table if exists Użytkownicy;
60
61/*==============================================================*/
62/* Table: ALPLI */
63/*==============================================================*/
64create table ALPLI
65(
66 IdALP int auto_increment not null,
67 IdAl int,
68 IdPli int,
69 primary key (IdALP)
70);
71
72/*==============================================================*/
73/* Table: ARTGRU */
74/*==============================================================*/
75create table ARTGRU
76(
77 IdAG int auto_increment not null,
78 IdAr int,
79 IdGr int,
80 primary key (IdAG)
81);
82
83/*==============================================================*/
84/* Table: ARTYALB */
85/*==============================================================*/
86create table ARTYALB
87(
88 IdAA int auto_increment not null,
89 IdAr int,
90 IdAl int,
91 primary key (IdAA)
92);
93
94/*==============================================================*/
95/* Table: ARTYPLI */
96/*==============================================================*/
97create table ARTYPLI
98(
99 IdARTP int auto_increment not null,
100 IdAr int,
101 IdPli int,
102 primary key (IdARTP)
103);
104
105/*==============================================================*/
106/* Table: Albumy */
107/*==============================================================*/
108create table Albumy
109(
110 IdAl int auto_increment not null,
111 Nazwa varchar(30) not null,
112 LiczbaUtworów smallint,
113 DataWydania date not null,
114 Ocena smallint,
115 Grafika longblob,
116 primary key (IdAl)
117);
118
119/*==============================================================*/
120/* Table: Artyści */
121/*==============================================================*/
122create table Artyści
123(
124 IdAr int auto_increment not null,
125 IdS int,
126 Nazwa varchar(30) not null,
127 ImiÄ™ varchar(30) not null,
128 Nazwisko varchar(30) not null,
129 Miasto varchar(30) not null,
130 Wiek smallint not null,
131 Telefon varchar(12) not null,
132 Email varchar(50) not null,
133 Zdjęcie longblob not null,
134 Opis text,
135 Ocena smallint,
136 primary key (IdAr)
137);
138
139/*==============================================================*/
140/* Table: CZUŻY */
141/*==============================================================*/
142create table CZUŻY
143(
144 IdCU int auto_increment not null,
145 IdC int,
146 IdU int,
147 primary key (IdCU)
148);
149
150/*==============================================================*/
151/* Table: Czaty */
152/*==============================================================*/
153create table Czaty
154(
155 IdC int auto_increment not null,
156 Zawartość text not null,
157 Data date not null,
158 primary key (IdC)
159);
160
161/*==============================================================*/
162/* Table: EVEART */
163/*==============================================================*/
164create table EVEART
165(
166 IdEA int auto_increment not null,
167 IdE int,
168 IdAr int,
169 primary key (IdEA)
170);
171
172/*==============================================================*/
173/* Table: EVEGRU */
174/*==============================================================*/
175create table EVEGRU
176(
177 IdEG int auto_increment not null,
178 IdE int,
179 IdGr int,
180 primary key (IdEG)
181);
182
183/*==============================================================*/
184/* Table: EVETAG */
185/*==============================================================*/
186create table EVETAG
187(
188 IdET int auto_increment not null,
189 IdE int,
190 IdT int,
191 primary key (IdET)
192);
193
194/*==============================================================*/
195/* Table: EVEUŻY */
196/*==============================================================*/
197create table EVEUŻY
198(
199 IdEU int auto_increment not null,
200 IdE int,
201 IdU int,
202 primary key (IdEU)
203);
204
205/*==============================================================*/
206/* Table: Eventy */
207/*==============================================================*/
208create table Eventy
209(
210 IdE int auto_increment not null,
211 Nazwa varchar(30) not null,
212 Lokalizacja varchar(30) not null,
213 Data date,
214 Godzina time,
215 Opis text,
216 primary key (IdE)
217);
218
219/*==============================================================*/
220/* Table: GRUTAG */
221/*==============================================================*/
222create table GRUTAG
223(
224 IdGT int auto_increment not null,
225 IdGr int,
226 IdT int,
227 primary key (IdGT)
228);
229
230/*==============================================================*/
231/* Table: GRUUŻY */
232/*==============================================================*/
233create table GRUUŻY
234(
235 IdGU int auto_increment not null,
236 IdU int,
237 IdGr int,
238 primary key (IdGU)
239);
240
241/*==============================================================*/
242/* Table: Gadżety */
243/*==============================================================*/
244create table Gadżety
245(
246 IdGat int auto_increment not null,
247 IdS int,
248 Nazwa varchar(30) not null,
249 Liczność int not null,
250 Cena float(8,2) not null,
251 Zdjęcie longblob not null,
252 Opis text,
253 primary key (IdGat)
254);
255
256/*==============================================================*/
257/* Table: Gatunki */
258/*==============================================================*/
259create table Gatunki
260(
261 IdGat int auto_increment not null,
262 Nazwa varchar(30) not null,
263 primary key (IdGat)
264);
265
266/*==============================================================*/
267/* Table: Grupy */
268/*==============================================================*/
269create table Grupy
270(
271 IdGr int auto_increment not null,
272 Nazwa varchar(30) not null,
273 Opis text,
274 Zdjęcie longblob,
275 primary key (IdGr)
276);
277
278/*==============================================================*/
279/* Table: PLAYTAG */
280/*==============================================================*/
281create table PLAYTAG
282(
283 IdPT int auto_increment not null,
284 IdPla int,
285 IdT int,
286 primary key (IdPT)
287);
288
289/*==============================================================*/
290/* Table: PLIPÅY */
291/*==============================================================*/
292create table PLIPÅY
293(
294 IdPP int auto_increment not null,
295 IdPli int,
296 IdPÅ‚ int,
297 primary key (IdPP)
298);
299
300/*==============================================================*/
301/* Table: Playlisty */
302/*==============================================================*/
303create table Playlisty
304(
305 IdPla int auto_increment not null,
306 Nazwa varchar(30) not null,
307 CzyPrywatna bool not null,
308 Ocena smallint,
309 Opis text,
310 primary key (IdPla)
311);
312
313/*==============================================================*/
314/* Table: Pliki */
315/*==============================================================*/
316create table Pliki
317(
318 IdPli int auto_increment not null,
319 IdGat int,
320 NazwaPliku varchar(30) not null,
321 TytułPliku varchar(30),
322 RokUtworzeniaPliku varchar(30),
323 NrUtworu smallint,
324 OcenaPliku smallint,
325 primary key (IdPli)
326);
327
328/*==============================================================*/
329/* Table: Posty */
330/*==============================================================*/
331create table Posty
332(
333 IdPo int auto_increment not null,
334 IdPla int,
335 IdAr int,
336 IdGr int,
337 IdU int,
338 IdGat int,
339 IdPÅ‚ int,
340 IdE int,
341 IdAl int,
342 IdPli int,
343 Data date not null,
344 Tekst text not null,
345 Zdjęcie longblob,
346 primary key (IdPo)
347);
348
349/*==============================================================*/
350/* Table: Płyty */
351/*==============================================================*/
352create table Płyty
353(
354 IdPÅ‚ int auto_increment not null,
355 IdS int,
356 Nazwa varchar(30),
357 LiczbaUtworów smallint,
358 Ocena smallint,
359 Grafika longblob,
360 Cena float(8,2),
361 Wykonawca varchar(30),
362 primary key (IdPÅ‚)
363);
364
365/*==============================================================*/
366/* Table: Sklepy */
367/*==============================================================*/
368create table Sklepy
369(
370 IdS int auto_increment not null,
371 Opis text,
372 Zdjęcie longblob,
373 primary key (IdS)
374);
375
376/*==============================================================*/
377/* Table: Tagi */
378/*==============================================================*/
379create table Tagi
380(
381 IdT int auto_increment not null,
382 Nazwa varchar(30) not null,
383 primary key (IdT)
384);
385
386/*==============================================================*/
387/* Table: UŻYART */
388/*==============================================================*/
389create table UŻYART
390(
391 IdUA int auto_increment not null,
392 IdU int,
393 IdAr int,
394 primary key (IdUA)
395);
396
397/*==============================================================*/
398/* Table: UŻYGRU */
399/*==============================================================*/
400create table UŻYGRU
401(
402 IdUG int auto_increment not null,
403 IdU int,
404 IdGr int,
405 primary key (IdUG)
406);
407
408/*==============================================================*/
409/* Table: UŻYUŻY */
410/*==============================================================*/
411create table UŻYUŻY
412(
413 IdUU int auto_increment not null,
414 IdU int,
415 Uży_IdU int,
416 primary key (IdUU)
417);
418
419/*==============================================================*/
420/* Table: Użytkownicy */
421/*==============================================================*/
422create table Użytkownicy
423(
424 IdU int auto_increment not null,
425 Nazwa varchar(30) not null,
426 Hasło varchar(30) not null,
427 DataUtworzenia date not null,
428 NumerTelefonu varchar(12),
429 Email varchar(50) not null,
430 ZdjęcieProfilowe longblob,
431 ImiÄ™ varchar(30),
432 Nazwisko varchar(30),
433 Miasto varchar(30),
434 Wiek smallint,
435 primary key (IdU)
436);
437
438alter table ALPLI add constraint FK_Relationship_36 foreign key (IdAl)
439 references Albumy (IdAl) on delete cascade on update restrict;
440
441alter table ALPLI add constraint FK_Relationship_37 foreign key (IdPli)
442 references Pliki (IdPli) on delete cascade on update restrict;
443
444alter table ARTGRU add constraint FK_Relationship_18 foreign key (IdAr)
445 references Artyści (IdAr) on delete cascade on update restrict;
446
447alter table ARTGRU add constraint FK_Relationship_19 foreign key (IdGr)
448 references Grupy (IdGr) on delete cascade on update restrict;
449
450alter table ARTYALB add constraint FK_Relationship_44 foreign key (IdAr)
451 references Artyści (IdAr) on delete cascade on update restrict;
452
453alter table ARTYALB add constraint FK_Relationship_45 foreign key (IdAl)
454 references Albumy (IdAl) on delete cascade on update restrict;
455
456alter table ARTYPLI add constraint FK_Relationship_40 foreign key (IdAr)
457 references Artyści (IdAr) on delete cascade on update restrict;
458
459alter table ARTYPLI add constraint FK_Relationship_41 foreign key (IdPli)
460 references Pliki (IdPli) on delete cascade on update restrict;
461
462alter table Artyści add constraint FK_Relationship_13 foreign key (IdS)
463 references Sklepy (IdS) on delete set null on update restrict;
464
465alter table CZUŻY add constraint FK_Relationship_34 foreign key (IdC)
466 references Czaty (IdC) on delete cascade on update restrict;
467
468alter table CZUŻY add constraint FK_Relationship_35 foreign key (IdU)
469 references Użytkownicy (IdU) on delete cascade on update restrict;
470
471alter table EVEART add constraint FK_Relationship_14 foreign key (IdE)
472 references Eventy (IdE) on delete cascade on update restrict;
473
474alter table EVEART add constraint FK_Relationship_15 foreign key (IdAr)
475 references Artyści (IdAr) on delete cascade on update restrict;
476
477alter table EVEGRU add constraint FK_Relationship_22 foreign key (IdE)
478 references Eventy (IdE) on delete cascade on update restrict;
479
480alter table EVEGRU add constraint FK_Relationship_23 foreign key (IdGr)
481 references Grupy (IdGr) on delete cascade on update restrict;
482
483alter table EVETAG add constraint FK_Relationship_20 foreign key (IdE)
484 references Eventy (IdE) on delete cascade on update restrict;
485
486alter table EVETAG add constraint FK_Relationship_21 foreign key (IdT)
487 references Tagi (IdT) on delete cascade on update restrict;
488
489alter table EVEUŻY add constraint FK_Relationship_24 foreign key (IdE)
490 references Eventy (IdE) on delete cascade on update restrict;
491
492alter table EVEUŻY add constraint FK_Relationship_25 foreign key (IdU)
493 references Użytkownicy (IdU) on delete cascade on update restrict;
494
495alter table GRUTAG add constraint FK_Relationship_32 foreign key (IdGr)
496 references Grupy (IdGr) on delete cascade on update restrict;
497
498alter table GRUTAG add constraint FK_Relationship_33 foreign key (IdT)
499 references Tagi (IdT) on delete cascade on update restrict;
500
501alter table GRUUŻY add constraint FK_Relationship_28 foreign key (IdU)
502 references Użytkownicy (IdU) on delete cascade on update restrict;
503
504alter table GRUUŻY add constraint FK_Relationship_29 foreign key (IdGr)
505 references Grupy (IdGr) on delete cascade on update restrict;
506
507alter table Gadżety add constraint FK_Relationship_10 foreign key (IdS)
508 references Sklepy (IdS) on delete cascade on update restrict;
509
510alter table PLAYTAG add constraint FK_Relationship_30 foreign key (IdPla)
511 references Playlisty (IdPla) on delete cascade on update restrict;
512
513alter table PLAYTAG add constraint FK_Relationship_31 foreign key (IdT)
514 references Tagi (IdT) on delete cascade on update restrict;
515
516alter table PLIPÅY add constraint FK_Relationship_38 foreign key (IdPli)
517 references Pliki (IdPli) on delete cascade on update restrict;
518
519alter table PLIPÅY add constraint FK_Relationship_39 foreign key (IdPÅ‚)
520 references Płyty (IdPł) on delete cascade on update restrict;
521
522alter table Pliki add constraint FK_Relationship_12 foreign key (IdGat)
523 references Gatunki (IdGat) on delete set null on update restrict;
524
525alter table Posty add constraint FK_Relationship_1 foreign key (IdPla)
526 references Playlisty (IdPla) on delete set null on update restrict;
527
528alter table Posty add constraint FK_Relationship_2 foreign key (IdAr)
529 references Artyści (IdAr) on delete set null on update restrict;
530
531alter table Posty add constraint FK_Relationship_3 foreign key (IdGr)
532 references Grupy (IdGr) on delete set null on update restrict;
533
534alter table Posty add constraint FK_Relationship_4 foreign key (IdU)
535 references Użytkownicy (IdU) on delete set null on update restrict;
536
537alter table Posty add constraint FK_Relationship_5 foreign key (IdGat)
538 references Gadżety (IdGat) on delete set null on update restrict;
539
540alter table Posty add constraint FK_Relationship_6 foreign key (IdPÅ‚)
541 references Płyty (IdPł) on delete set null on update restrict;
542
543alter table Posty add constraint FK_Relationship_7 foreign key (IdE)
544 references Eventy (IdE) on delete set null on update restrict;
545
546alter table Posty add constraint FK_Relationship_8 foreign key (IdAl)
547 references Albumy (IdAl) on delete set null on update restrict;
548
549alter table Posty add constraint FK_Relationship_9 foreign key (IdPli)
550 references Pliki (IdPli) on delete set null on update restrict;
551
552alter table Płyty add constraint FK_Relationship_11 foreign key (IdS)
553 references Sklepy (IdS) on delete cascade on update restrict;
554
555alter table UŻYART add constraint FK_Relationship_16 foreign key (IdU)
556 references Użytkownicy (IdU) on delete cascade on update restrict;
557
558alter table UŻYART add constraint FK_Relationship_17 foreign key (IdAr)
559 references Artyści (IdAr) on delete cascade on update restrict;
560
561alter table UŻYGRU add constraint FK_Relationship_26 foreign key (IdU)
562 references Użytkownicy (IdU) on delete cascade on update restrict;
563
564alter table UŻYGRU add constraint FK_Relationship_27 foreign key (IdGr)
565 references Grupy (IdGr) on delete cascade on update restrict;
566
567alter table UŻYUŻY add constraint FK_Relationship_42 foreign key (IdU)
568 references Użytkownicy (IdU) on delete cascade on update restrict;
569
570alter table UŻYUŻY add constraint FK_Relationship_43 foreign key (Uży_IdU)
571 references Użytkownicy (IdU) on delete cascade on update restrict;