· 8 years ago · May 10, 2018, 12:46 PM
1/*==============================================================*/
2/* DBMS name: SAP SQL Anywhere 16 */
3/* Created on: 2018-05-10 14:42:14 */
4/*==============================================================*/
5
6
7if exists(select 1 from sys.sysforeignkey where role='FK_ADRES_ADRES_MIA_MIASTO') then
8 alter table Adres
9 delete foreign key FK_ADRES_ADRES_MIA_MIASTO
10end if;
11
12if exists(select 1 from sys.sysforeignkey where role='FK_ADRES_ADRES_WOJ_WOJEWODZ') then
13 alter table Adres
14 delete foreign key FK_ADRES_ADRES_WOJ_WOJEWODZ
15end if;
16
17if exists(select 1 from sys.sysforeignkey where role='FK_ADRES_RELATIONS_KODPOCZT') then
18 alter table Adres
19 delete foreign key FK_ADRES_RELATIONS_KODPOCZT
20end if;
21
22if exists(select 1 from sys.sysforeignkey where role='FK_BILET_,._TYPBILET') then
23 alter table Bilet
24 delete foreign key "FK_BILET_,._TYPBILET"
25end if;
26
27if exists(select 1 from sys.sysforeignkey where role='FK_BILET_.._ULGA') then
28 alter table Bilet
29 delete foreign key "FK_BILET_.._ULGA"
30end if;
31
32if exists(select 1 from sys.sysforeignkey where role='FK_BILET_BILET_UZY_UZYTKOWN') then
33 alter table Bilet
34 delete foreign key FK_BILET_BILET_UZY_UZYTKOWN
35end if;
36
37if exists(select 1 from sys.sysforeignkey where role='FK_BILET_RELATIONS_STREFA') then
38 alter table Bilet
39 delete foreign key FK_BILET_RELATIONS_STREFA
40end if;
41
42if exists(select 1 from sys.sysforeignkey where role='FK_DLUZNIK_DLUZNIK_A_ADRES') then
43 alter table Dluznik
44 delete foreign key FK_DLUZNIK_DLUZNIK_A_ADRES
45end if;
46
47if exists(select 1 from sys.sysforeignkey where role='FK_KARTAMIE_KARTAMIEJ_STREFA') then
48 alter table KartaMiejska
49 delete foreign key FK_KARTAMIE_KARTAMIEJ_STREFA
50end if;
51
52if exists(select 1 from sys.sysforeignkey where role='FK_KARTAMIE_KARTAMIEJ_ULGA') then
53 alter table KartaMiejska
54 delete foreign key FK_KARTAMIE_KARTAMIEJ_ULGA
55end if;
56
57if exists(select 1 from sys.sysforeignkey where role='FK_KARTAMIE_KARTAMIEJ_UZYTKOWN') then
58 alter table KartaMiejska
59 delete foreign key FK_KARTAMIE_KARTAMIEJ_UZYTKOWN
60end if;
61
62if exists(select 1 from sys.sysforeignkey where role='FK_KARTAMIE_RELATIONS_TYPKARTA') then
63 alter table KartaMiejska
64 delete foreign key FK_KARTAMIE_RELATIONS_TYPKARTA
65end if;
66
67if exists(select 1 from sys.sysforeignkey where role='FK_KONTROLE_KONTROLER_REJON') then
68 alter table Kontroler
69 delete foreign key FK_KONTROLE_KONTROLER_REJON
70end if;
71
72if exists(select 1 from sys.sysforeignkey where role='FK_MANDAT_MANDAT_DL_DLUZNIK') then
73 alter table Mandat
74 delete foreign key FK_MANDAT_MANDAT_DL_DLUZNIK
75end if;
76
77if exists(select 1 from sys.sysforeignkey where role='FK_MANDAT_MANDAT_KO_KONTROLE') then
78 alter table Mandat
79 delete foreign key FK_MANDAT_MANDAT_KO_KONTROLE
80end if;
81
82if exists(select 1 from sys.sysforeignkey where role='FK_MANDAT_MANDAT_TY_TYPMANDA') then
83 alter table Mandat
84 delete foreign key FK_MANDAT_MANDAT_TY_TYPMANDA
85end if;
86
87if exists(select 1 from sys.sysforeignkey where role='FK_UZYTKOWN_UZYTKOWNI_UPRAWNIE') then
88 alter table Uzytkownik
89 delete foreign key FK_UZYTKOWN_UZYTKOWNI_UPRAWNIE
90end if;
91
92drop index if exists Adres.Relationship_18_FK;
93
94drop index if exists Adres.Relationship_15_FK;
95
96drop index if exists Adres.Relationship_14_FK;
97
98drop index if exists Adres.Adres_PK;
99
100drop table if exists Adres;
101
102drop index if exists Bilet.Bilet_Uzytkownik_FK;
103
104drop index if exists Bilet.Relationship_11_FK;
105
106drop index if exists Bilet.",._FK";
107
108drop index if exists Bilet.".._FK";
109
110drop index if exists Bilet.Bilet_PK;
111
112drop table if exists Bilet;
113
114drop index if exists Dluznik.Relationship_3_FK;
115
116drop index if exists Dluznik.Dluznik_PK;
117
118drop table if exists Dluznik;
119
120drop index if exists KartaMiejska.KartaMiejska_Uzytkownik_FK;
121
122drop index if exists KartaMiejska."._FK";
123
124drop index if exists KartaMiejska.,_FK;
125
126drop index if exists KartaMiejska.Relationship_13_FK;
127
128drop index if exists KartaMiejska.KartaMiejska_PK;
129
130drop table if exists KartaMiejska;
131
132drop index if exists KodPocztowy.KodPocztowy_PK;
133
134drop table if exists KodPocztowy;
135
136drop index if exists Kontroler.Relationship_9_FK;
137
138drop index if exists Kontroler.Kontroler_PK;
139
140drop table if exists Kontroler;
141
142drop index if exists Mandat.Relationship_12_FK;
143
144drop index if exists Mandat.Relationship_5_FK;
145
146drop index if exists Mandat.Relationship_1_FK;
147
148drop index if exists Mandat.Mandat_PK;
149
150drop table if exists Mandat;
151
152drop index if exists Miasto.Miasto_PK;
153
154drop table if exists Miasto;
155
156drop index if exists Rejon.Rejon_PK;
157
158drop table if exists Rejon;
159
160drop index if exists Strefa.Strefa_PK;
161
162drop table if exists Strefa;
163
164drop index if exists TypBiletu.TypBiletu_PK;
165
166drop table if exists TypBiletu;
167
168drop index if exists TypKartaMiejska.TypKartaMiejska_PK;
169
170drop table if exists TypKartaMiejska;
171
172drop index if exists TypMandatu.TypMandatu_PK;
173
174drop table if exists TypMandatu;
175
176drop index if exists Ulga.Ulga_PK;
177
178drop table if exists Ulga;
179
180drop index if exists Uprawnienia.Uprawnienia_PK;
181
182drop table if exists Uprawnienia;
183
184drop index if exists Uzytkownik.Uzytkownik_Uprawnienia_FK;
185
186drop index if exists Uzytkownik.Uzytkownik_PK;
187
188drop table if exists Uzytkownik;
189
190drop index if exists Wojewodztwo.Wojewodztwo_PK;
191
192drop table if exists Wojewodztwo;
193
194/*==============================================================*/
195/* Table: Adres */
196/*==============================================================*/
197create table Adres
198(
199 AdresID integer not null,
200 WojewodztwoID integer null,
201 MiastoID integer null,
202 KodPocztowyID integer null,
203 Ulica varchar(40) null,
204 UlicaNr varchar(4) null,
205 MieszkanieNr varchar(6) null,
206 constraint PK_ADRES primary key (AdresID)
207);
208
209/*==============================================================*/
210/* Index: Adres_PK */
211/*==============================================================*/
212create unique index Adres_PK on Adres (
213AdresID ASC
214);
215
216/*==============================================================*/
217/* Index: Relationship_14_FK */
218/*==============================================================*/
219create index Relationship_14_FK on Adres (
220WojewodztwoID ASC
221);
222
223/*==============================================================*/
224/* Index: Relationship_15_FK */
225/*==============================================================*/
226create index Relationship_15_FK on Adres (
227MiastoID ASC
228);
229
230/*==============================================================*/
231/* Index: Relationship_18_FK */
232/*==============================================================*/
233create index Relationship_18_FK on Adres (
234KodPocztowyID ASC
235);
236
237/*==============================================================*/
238/* Table: Bilet */
239/*==============================================================*/
240create table Bilet
241(
242 BiletID varchar(50) not null,
243 TypID integer not null,
244 UlgaID integer not null,
245 StrefaID integer not null,
246 UzytkownikID integer null,
247 WaznyOd timestamp null,
248 WaznyDo timestamp null,
249 Kwota numeric(7) not null,
250 constraint PK_BILET primary key (BiletID)
251);
252
253/*==============================================================*/
254/* Index: Bilet_PK */
255/*==============================================================*/
256create unique index Bilet_PK on Bilet (
257BiletID ASC
258);
259
260/*==============================================================*/
261/* Index: ".._FK" */
262/*==============================================================*/
263create index ".._FK" on Bilet (
264UlgaID ASC
265);
266
267/*==============================================================*/
268/* Index: ",._FK" */
269/*==============================================================*/
270create index ",._FK" on Bilet (
271TypID ASC
272);
273
274/*==============================================================*/
275/* Index: Relationship_11_FK */
276/*==============================================================*/
277create index Relationship_11_FK on Bilet (
278StrefaID ASC
279);
280
281/*==============================================================*/
282/* Index: Bilet_Uzytkownik_FK */
283/*==============================================================*/
284create index Bilet_Uzytkownik_FK on Bilet (
285UzytkownikID ASC
286);
287
288/*==============================================================*/
289/* Table: Dluznik */
290/*==============================================================*/
291create table Dluznik
292(
293 DluznikID integer not null,
294 Imie varchar(50) not null,
295 Nazwisko varchar(50) not null,
296 PESEL varchar(20) not null,
297 AdresID integer not null,
298 Email varchar(40) null,
299 constraint PK_DLUZNIK primary key (DluznikID)
300);
301
302/*==============================================================*/
303/* Index: Dluznik_PK */
304/*==============================================================*/
305create unique index Dluznik_PK on Dluznik (
306DluznikID ASC
307);
308
309/*==============================================================*/
310/* Index: Relationship_3_FK */
311/*==============================================================*/
312create index Relationship_3_FK on Dluznik (
313AdresID ASC
314);
315
316/*==============================================================*/
317/* Table: KartaMiejska */
318/*==============================================================*/
319create table KartaMiejska
320(
321 KartaMiejskaID integer not null,
322 TypKartaMiejskaID integer not null,
323 StrefaID integer not null,
324 UlgaID integer not null,
325 UzytkownikID integer null,
326 Email varchar(50) not null,
327 WaznyOd timestamp null,
328 WaznyDo timestamp null,
329 Aktywna smallint not null,
330 constraint PK_KARTAMIEJSKA primary key (KartaMiejskaID)
331);
332
333/*==============================================================*/
334/* Index: KartaMiejska_PK */
335/*==============================================================*/
336create unique index KartaMiejska_PK on KartaMiejska (
337KartaMiejskaID ASC
338);
339
340/*==============================================================*/
341/* Index: Relationship_13_FK */
342/*==============================================================*/
343create index Relationship_13_FK on KartaMiejska (
344TypKartaMiejskaID ASC
345);
346
347/*==============================================================*/
348/* Index: ,_FK */
349/*==============================================================*/
350create index ,_FK on KartaMiejska (
351StrefaID ASC
352);
353
354/*==============================================================*/
355/* Index: "._FK" */
356/*==============================================================*/
357create index "._FK" on KartaMiejska (
358UlgaID ASC
359);
360
361/*==============================================================*/
362/* Index: KartaMiejska_Uzytkownik_FK */
363/*==============================================================*/
364create index KartaMiejska_Uzytkownik_FK on KartaMiejska (
365UzytkownikID ASC
366);
367
368/*==============================================================*/
369/* Table: KodPocztowy */
370/*==============================================================*/
371create table KodPocztowy
372(
373 KodPocztowyID integer not null,
374 Nazwa char(6) not null,
375 constraint PK_KODPOCZTOWY primary key (KodPocztowyID)
376);
377
378/*==============================================================*/
379/* Index: KodPocztowy_PK */
380/*==============================================================*/
381create unique index KodPocztowy_PK on KodPocztowy (
382KodPocztowyID ASC
383);
384
385/*==============================================================*/
386/* Table: Kontroler */
387/*==============================================================*/
388create table Kontroler
389(
390 KontrolerID integer not null,
391 Imie varchar(50) not null,
392 Nazwisko varchar(50) not null,
393 PESEL char(11) not null,
394 RejonID integer not null,
395 Email varchar(50) not null,
396 Haslo varchar(50) not null,
397 constraint PK_KONTROLER primary key (KontrolerID)
398);
399
400/*==============================================================*/
401/* Index: Kontroler_PK */
402/*==============================================================*/
403create unique index Kontroler_PK on Kontroler (
404KontrolerID ASC
405);
406
407/*==============================================================*/
408/* Index: Relationship_9_FK */
409/*==============================================================*/
410create index Relationship_9_FK on Kontroler (
411RejonID ASC
412);
413
414/*==============================================================*/
415/* Table: Mandat */
416/*==============================================================*/
417create table Mandat
418(
419 MandatID integer not null,
420 TypID integer not null,
421 TerminPlatnosci timestamp null,
422 DataWystawienia timestamp null,
423 CzyZaplacony smallint not null,
424 NumerKonta char(26) null,
425 DluznikID integer not null,
426 KontrolerID integer not null,
427 constraint PK_MANDAT primary key (MandatID)
428);
429
430/*==============================================================*/
431/* Index: Mandat_PK */
432/*==============================================================*/
433create unique index Mandat_PK on Mandat (
434MandatID ASC
435);
436
437/*==============================================================*/
438/* Index: Relationship_1_FK */
439/*==============================================================*/
440create index Relationship_1_FK on Mandat (
441DluznikID ASC
442);
443
444/*==============================================================*/
445/* Index: Relationship_5_FK */
446/*==============================================================*/
447create index Relationship_5_FK on Mandat (
448KontrolerID ASC
449);
450
451/*==============================================================*/
452/* Index: Relationship_12_FK */
453/*==============================================================*/
454create index Relationship_12_FK on Mandat (
455TypID ASC
456);
457
458/*==============================================================*/
459/* Table: Miasto */
460/*==============================================================*/
461create table Miasto
462(
463 MiastoID integer not null,
464 Nazwa varchar(40) not null,
465 constraint PK_MIASTO primary key (MiastoID)
466);
467
468/*==============================================================*/
469/* Index: Miasto_PK */
470/*==============================================================*/
471create unique index Miasto_PK on Miasto (
472MiastoID ASC
473);
474
475/*==============================================================*/
476/* Table: Rejon */
477/*==============================================================*/
478create table Rejon
479(
480 RejonID integer not null,
481 NazwaRejonu varchar(50) not null,
482 constraint PK_REJON primary key (RejonID)
483);
484
485/*==============================================================*/
486/* Index: Rejon_PK */
487/*==============================================================*/
488create unique index Rejon_PK on Rejon (
489RejonID ASC
490);
491
492/*==============================================================*/
493/* Table: Strefa */
494/*==============================================================*/
495create table Strefa
496(
497 StrefaID integer not null,
498 NazwaStrefa varchar(10) not null,
499 constraint PK_STREFA primary key (StrefaID)
500);
501
502/*==============================================================*/
503/* Index: Strefa_PK */
504/*==============================================================*/
505create unique index Strefa_PK on Strefa (
506StrefaID ASC
507);
508
509/*==============================================================*/
510/* Table: TypBiletu */
511/*==============================================================*/
512create table TypBiletu
513(
514 TypID integer not null,
515 NazwaTyp varchar(50) not null,
516 constraint PK_TYPBILETU primary key (TypID)
517);
518
519/*==============================================================*/
520/* Index: TypBiletu_PK */
521/*==============================================================*/
522create unique index TypBiletu_PK on TypBiletu (
523TypID ASC
524);
525
526/*==============================================================*/
527/* Table: TypKartaMiejska */
528/*==============================================================*/
529create table TypKartaMiejska
530(
531 TypKartaMiejskaID integer not null,
532 Nazwa varchar(20) not null,
533 constraint PK_TYPKARTAMIEJSKA primary key (TypKartaMiejskaID)
534);
535
536/*==============================================================*/
537/* Index: TypKartaMiejska_PK */
538/*==============================================================*/
539create unique index TypKartaMiejska_PK on TypKartaMiejska (
540TypKartaMiejskaID ASC
541);
542
543/*==============================================================*/
544/* Table: TypMandatu */
545/*==============================================================*/
546create table TypMandatu
547(
548 TypID integer not null,
549 NazwaTyp varchar(50) not null,
550 Kwota numeric(8) not null,
551 constraint PK_TYPMANDATU primary key (TypID)
552);
553
554/*==============================================================*/
555/* Index: TypMandatu_PK */
556/*==============================================================*/
557create unique index TypMandatu_PK on TypMandatu (
558TypID ASC
559);
560
561/*==============================================================*/
562/* Table: Ulga */
563/*==============================================================*/
564create table Ulga
565(
566 UlgaID integer not null,
567 RodzajUlgi varchar(50) not null,
568 Znizka float not null,
569 constraint PK_ULGA primary key (UlgaID)
570);
571
572/*==============================================================*/
573/* Index: Ulga_PK */
574/*==============================================================*/
575create unique index Ulga_PK on Ulga (
576UlgaID ASC
577);
578
579/*==============================================================*/
580/* Table: Uprawnienia */
581/*==============================================================*/
582create table Uprawnienia
583(
584 UprawnieniaID integer not null,
585 Nazwa varchar(20) not null,
586 constraint PK_UPRAWNIENIA primary key (UprawnieniaID)
587);
588
589/*==============================================================*/
590/* Index: Uprawnienia_PK */
591/*==============================================================*/
592create unique index Uprawnienia_PK on Uprawnienia (
593UprawnieniaID ASC
594);
595
596/*==============================================================*/
597/* Table: Uzytkownik */
598/*==============================================================*/
599create table Uzytkownik
600(
601 UzytkownikID integer not null,
602 UprawnieniaID integer null,
603 Imie varchar(50) not null,
604 Nazwisko varchar(50) not null,
605 Email varchar(50) not null,
606 Haslo varchar(50) not null,
607 constraint PK_UZYTKOWNIK primary key (UzytkownikID)
608);
609
610/*==============================================================*/
611/* Index: Uzytkownik_PK */
612/*==============================================================*/
613create unique index Uzytkownik_PK on Uzytkownik (
614UzytkownikID ASC
615);
616
617/*==============================================================*/
618/* Index: Uzytkownik_Uprawnienia_FK */
619/*==============================================================*/
620create index Uzytkownik_Uprawnienia_FK on Uzytkownik (
621UprawnieniaID ASC
622);
623
624/*==============================================================*/
625/* Table: Wojewodztwo */
626/*==============================================================*/
627create table Wojewodztwo
628(
629 WojewodztwoID integer not null,
630 Nazwa varchar(30) not null,
631 constraint PK_WOJEWODZTWO primary key (WojewodztwoID)
632);
633
634/*==============================================================*/
635/* Index: Wojewodztwo_PK */
636/*==============================================================*/
637create unique index Wojewodztwo_PK on Wojewodztwo (
638WojewodztwoID ASC
639);
640
641alter table Adres
642 add constraint FK_ADRES_ADRES_MIA_MIASTO foreign key (MiastoID)
643 references Miasto (MiastoID)
644 on update restrict
645 on delete restrict;
646
647alter table Adres
648 add constraint FK_ADRES_ADRES_WOJ_WOJEWODZ foreign key (WojewodztwoID)
649 references Wojewodztwo (WojewodztwoID)
650 on update restrict
651 on delete restrict;
652
653alter table Adres
654 add constraint FK_ADRES_RELATIONS_KODPOCZT foreign key (KodPocztowyID)
655 references KodPocztowy (KodPocztowyID)
656 on update restrict
657 on delete restrict;
658
659alter table Bilet
660 add constraint "FK_BILET_,._TYPBILET" foreign key (TypID)
661 references TypBiletu (TypID)
662 on update restrict
663 on delete restrict;
664
665alter table Bilet
666 add constraint "FK_BILET_.._ULGA" foreign key (UlgaID)
667 references Ulga (UlgaID)
668 on update restrict
669 on delete restrict;
670
671alter table Bilet
672 add constraint FK_BILET_BILET_UZY_UZYTKOWN foreign key (UzytkownikID)
673 references Uzytkownik (UzytkownikID)
674 on update restrict
675 on delete restrict;
676
677alter table Bilet
678 add constraint FK_BILET_RELATIONS_STREFA foreign key (StrefaID)
679 references Strefa (StrefaID)
680 on update restrict
681 on delete restrict;
682
683alter table Dluznik
684 add constraint FK_DLUZNIK_DLUZNIK_A_ADRES foreign key (AdresID)
685 references Adres (AdresID)
686 on update restrict
687 on delete restrict;
688
689alter table KartaMiejska
690 add constraint FK_KARTAMIE_KARTAMIEJ_STREFA foreign key (StrefaID)
691 references Strefa (StrefaID)
692 on update restrict
693 on delete restrict;
694
695alter table KartaMiejska
696 add constraint FK_KARTAMIE_KARTAMIEJ_ULGA foreign key (UlgaID)
697 references Ulga (UlgaID)
698 on update restrict
699 on delete restrict;
700
701alter table KartaMiejska
702 add constraint FK_KARTAMIE_KARTAMIEJ_UZYTKOWN foreign key (UzytkownikID)
703 references Uzytkownik (UzytkownikID)
704 on update restrict
705 on delete restrict;
706
707alter table KartaMiejska
708 add constraint FK_KARTAMIE_RELATIONS_TYPKARTA foreign key (TypKartaMiejskaID)
709 references TypKartaMiejska (TypKartaMiejskaID)
710 on update restrict
711 on delete restrict;
712
713alter table Kontroler
714 add constraint FK_KONTROLE_KONTROLER_REJON foreign key (RejonID)
715 references Rejon (RejonID)
716 on update restrict
717 on delete restrict;
718
719alter table Mandat
720 add constraint FK_MANDAT_MANDAT_DL_DLUZNIK foreign key (DluznikID)
721 references Dluznik (DluznikID)
722 on update restrict
723 on delete restrict;
724
725alter table Mandat
726 add constraint FK_MANDAT_MANDAT_KO_KONTROLE foreign key (KontrolerID)
727 references Kontroler (KontrolerID)
728 on update restrict
729 on delete restrict;
730
731alter table Mandat
732 add constraint FK_MANDAT_MANDAT_TY_TYPMANDA foreign key (TypID)
733 references TypMandatu (TypID)
734 on update restrict
735 on delete restrict;
736
737alter table Uzytkownik
738 add constraint FK_UZYTKOWN_UZYTKOWNI_UPRAWNIE foreign key (UprawnieniaID)
739 references Uprawnienia (UprawnieniaID)
740 on update restrict
741 on delete restrict;