· 9 years ago · Dec 07, 2016, 07:12 PM
1/*==============================================================*/
2/* DBMS name: SAP SQL Anywhere 16 */
3/* Created on: 27.10.2016 11:03:55 */
4/*==============================================================*/
5
6
7if exists(select 1 from sys.sysforeignkey where role='FK_POSZKODO_RELATIONS_WEZWANIA') then
8 alter table Poszkodowani
9 delete foreign key FK_POSZKODO_RELATIONS_WEZWANIA
10end if;
11
12if exists(select 1 from sys.sysforeignkey where role='FK_POSZKODO_RELATIONS_PACJENCI') then
13 alter table Poszkodowani
14 delete foreign key FK_POSZKODO_RELATIONS_PACJENCI
15end if;
16
17if exists(select 1 from sys.sysforeignkey where role='FK_POSZKODO_RELATIONS_KODY') then
18 alter table Poszkodowani
19 delete foreign key FK_POSZKODO_RELATIONS_KODY
20end if;
21
22if exists(select 1 from sys.sysforeignkey where role='FK_POSZKODO_RELATIONS_SZPITALE') then
23 alter table Poszkodowani
24 delete foreign key FK_POSZKODO_RELATIONS_SZPITALE
25end if;
26
27if exists(select 1 from sys.sysforeignkey where role='FK_ULICE_RELATIONS_PODSTACJ') then
28 alter table Ulice
29 delete foreign key FK_ULICE_RELATIONS_PODSTACJ
30end if;
31
32if exists(select 1 from sys.sysforeignkey where role='FK_ULICE_RELATIONS_MIEJSCOW') then
33 alter table Ulice
34 delete foreign key FK_ULICE_RELATIONS_MIEJSCOW
35end if;
36
37if exists(select 1 from sys.sysforeignkey where role='FK_WEZWANIA_RELATIONS_ZGLOSZEN') then
38 alter table Wezwania
39 delete foreign key FK_WEZWANIA_RELATIONS_ZGLOSZEN
40end if;
41
42if exists(select 1 from sys.sysforeignkey where role='FK_WYKONANE_RELATIONS_WEZWANIA') then
43 alter table "Wykonane procedury"
44 delete foreign key FK_WYKONANE_RELATIONS_WEZWANIA
45end if;
46
47if exists(select 1 from sys.sysforeignkey where role='FK_WYKONANE_RELATIONS_PROCEDUR') then
48 alter table "Wykonane procedury"
49 delete foreign key FK_WYKONANE_RELATIONS_PROCEDUR
50end if;
51
52if exists(select 1 from sys.sysforeignkey where role='FK_ZATRUDNI_RELATIONS_ZESPOLY') then
53 alter table "Zatrudnieni pracownicy"
54 delete foreign key FK_ZATRUDNI_RELATIONS_ZESPOLY
55end if;
56
57if exists(select 1 from sys.sysforeignkey where role='FK_ZATRUDNI_RELATIONS_PRACOWNI') then
58 alter table "Zatrudnieni pracownicy"
59 delete foreign key FK_ZATRUDNI_RELATIONS_PRACOWNI
60end if;
61
62if exists(select 1 from sys.sysforeignkey where role='FK_ZESPOLY _RELATIONS_WEZWANIA') then
63 alter table "Zespoly do wezwania"
64 delete foreign key "FK_ZESPOLY _RELATIONS_WEZWANIA"
65end if;
66
67if exists(select 1 from sys.sysforeignkey where role='FK_ZESPOLY _RELATIONS_ZESPOLY') then
68 alter table "Zespoly do wezwania"
69 delete foreign key "FK_ZESPOLY _RELATIONS_ZESPOLY"
70end if;
71
72if exists(select 1 from sys.sysforeignkey where role='FK_ZESPOLY _RELATIONS_KARETKI') then
73 alter table "Zespoly ratownictwa medycznego"
74 delete foreign key "FK_ZESPOLY _RELATIONS_KARETKI"
75end if;
76
77if exists(select 1 from sys.sysforeignkey where role='FK_ZESPOLY _RELATIONS_PODSTACJ') then
78 alter table "Zespoly ratownictwa medycznego"
79 delete foreign key "FK_ZESPOLY _RELATIONS_PODSTACJ"
80end if;
81
82if exists(select 1 from sys.sysforeignkey where role='FK_ZGLOSZEN_RELATIONS_DYSPOZYT') then
83 alter table Zgloszenia
84 delete foreign key FK_ZGLOSZEN_RELATIONS_DYSPOZYT
85end if;
86
87drop index if exists Dyspozytorzy.Dyspozytorzy_PK;
88
89drop table if exists Dyspozytorzy;
90
91drop index if exists Karetki.Karetki_PK;
92
93drop table if exists Karetki;
94
95drop index if exists Kody.Kody_PK;
96
97drop table if exists Kody;
98
99drop index if exists Miejscowosci.Miejscowości_PK;
100
101drop table if exists Miejscowosci;
102
103drop index if exists Pacjenci.Pacjenci_PK;
104
105drop table if exists Pacjenci;
106
107drop index if exists Podstacje.Podstacje_PK;
108
109drop table if exists Podstacje;
110
111drop index if exists Poszkodowani.Relationship_9_FK;
112
113drop index if exists Poszkodowani.Relationship_8_FK;
114
115drop index if exists Poszkodowani.Relationship_7_FK;
116
117drop index if exists Poszkodowani.Relationship_6_FK;
118
119drop index if exists Poszkodowani.Poszkodowani_PK;
120
121drop table if exists Poszkodowani;
122
123drop index if exists Pracownicy.Pracownicy_PK;
124
125drop table if exists Pracownicy;
126
127drop index if exists Procedury.Procedury_PK;
128
129drop table if exists Procedury;
130
131drop index if exists Szpitale.Szpitale_PK;
132
133drop table if exists Szpitale;
134
135drop index if exists Ulice.Relationship_16_FK;
136
137drop index if exists Ulice.Relationship_1_FK;
138
139drop index if exists Ulice.Ulice_PK;
140
141drop table if exists Ulice;
142
143drop index if exists Wezwania.Relationship_11_FK;
144
145drop index if exists Wezwania.Wezwania_PK;
146
147drop table if exists Wezwania;
148
149drop index if exists "Wykonane procedury".Relationship_4_FK;
150
151drop index if exists "Wykonane procedury".Relationship_3_FK;
152
153drop index if exists "Wykonane procedury"."Wykonane procedury_PK";
154
155drop table if exists "Wykonane procedury";
156
157drop index if exists "Zatrudnieni pracownicy".Relationship_2_FK;
158
159drop index if exists "Zatrudnieni pracownicy".Relationship_1_FK;
160
161drop index if exists "Zatrudnieni pracownicy"."Zatrudnieni pracownicy_PK";
162
163drop table if exists "Zatrudnieni pracownicy";
164
165drop index if exists "Zespoly do wezwania".Relationship_12_FK;
166
167drop index if exists "Zespoly do wezwania".Relationship_10_FK;
168
169drop index if exists "Zespoly do wezwania"."Zespoły do wezwania_PK";
170
171drop table if exists "Zespoly do wezwania";
172
173drop index if exists "Zespoly ratownictwa medycznego".Relationship_14_FK;
174
175drop index if exists "Zespoly ratownictwa medycznego".Relationship_13_FK;
176
177drop index if exists "Zespoly ratownictwa medycznego"."Zespoły ratownictwa medycznego_PK";
178
179drop table if exists "Zespoly ratownictwa medycznego";
180
181drop index if exists Zgloszenia.Relationship_5_FK;
182
183drop index if exists Zgloszenia.Zgłoszenia_PK;
184
185drop table if exists Zgloszenia;
186
187/*==============================================================*/
188/* Table: Dyspozytorzy */
189/*==============================================================*/
190create table Dyspozytorzy
191(
192 IdDyspozytora integer not null,
193 Imie long varchar null,
194 Nazwisko long varchar null,
195 NrDomu long varchar null,
196 NrMieszkania long varchar null,
197 KodPocztowy long varchar null,
198 Poczta long varchar null,
199 PESEL integer null,
200 DataUrodzenia date null,
201 MiejsceUrodzenia long varchar null,
202 "E-mail" long varchar null,
203 Telefon integer null,
204 constraint PK_DYSPOZYTORZY primary key (IdDyspozytora)
205);
206
207/*==============================================================*/
208/* Index: Dyspozytorzy_PK */
209/*==============================================================*/
210create unique index Dyspozytorzy_PK on Dyspozytorzy (
211IdDyspozytora ASC
212);
213
214/*==============================================================*/
215/* Table: Karetki */
216/*==============================================================*/
217create table Karetki
218(
219 IdKaretki integer not null,
220 NrKaretki long varchar null,
221 Rodzaj long varchar null,
222 NrVIN long varchar not null,
223 NrRej long varchar not null,
224 constraint PK_KARETKI primary key (IdKaretki)
225);
226
227/*==============================================================*/
228/* Index: Karetki_PK */
229/*==============================================================*/
230create unique index Karetki_PK on Karetki (
231IdKaretki ASC
232);
233
234/*==============================================================*/
235/* Table: Kody */
236/*==============================================================*/
237create table Kody
238(
239 IdKodu integer not null,
240 OpisK long varchar null,
241 constraint PK_KODY primary key (IdKodu)
242);
243
244/*==============================================================*/
245/* Index: Kody_PK */
246/*==============================================================*/
247create unique index Kody_PK on Kody (
248IdKodu ASC
249);
250
251/*==============================================================*/
252/* Table: Miejscowosci */
253/*==============================================================*/
254create table Miejscowosci
255(
256 IdMiejscowosci integer not null,
257 NazwaMiejscowosci long varchar null,
258 constraint PK_MIEJSCOWOSCI primary key (IdMiejscowosci)
259);
260
261/*==============================================================*/
262/* Index: Miejscowości_PK */
263/*==============================================================*/
264create unique index Miejscowości_PK on Miejscowosci (
265IdMiejscowosci ASC
266);
267
268/*==============================================================*/
269/* Table: Pacjenci */
270/*==============================================================*/
271create table Pacjenci
272(
273 IdPacjenta integer not null,
274 PESEL integer null,
275 constraint PK_PACJENCI primary key (IdPacjenta)
276);
277
278/*==============================================================*/
279/* Index: Pacjenci_PK */
280/*==============================================================*/
281create unique index Pacjenci_PK on Pacjenci (
282IdPacjenta ASC
283);
284
285/*==============================================================*/
286/* Table: Podstacje */
287/*==============================================================*/
288create table Podstacje
289(
290 IdStacji integer not null,
291 NrDomu long varchar null,
292 KodPocztowy long varchar null,
293 Poczta long varchar null,
294 Telefon integer null,
295 constraint PK_PODSTACJE primary key clustered (IdStacji)
296);
297
298/*==============================================================*/
299/* Index: Podstacje_PK */
300/*==============================================================*/
301create unique clustered index Podstacje_PK on Podstacje (
302IdStacji ASC
303);
304
305/*==============================================================*/
306/* Table: Poszkodowani */
307/*==============================================================*/
308create table Poszkodowani
309(
310 IdWezwania integer not null,
311 IdPacjenta integer not null,
312 IdKodu integer null,
313 IdSzpitala integer null,
314 constraint PK_POSZKODOWANI primary key (IdWezwania, IdPacjenta)
315);
316
317/*==============================================================*/
318/* Index: Poszkodowani_PK */
319/*==============================================================*/
320create unique index Poszkodowani_PK on Poszkodowani (
321IdWezwania ASC,
322IdPacjenta ASC
323);
324
325/*==============================================================*/
326/* Index: Relationship_6_FK */
327/*==============================================================*/
328create index Relationship_6_FK on Poszkodowani (
329IdWezwania ASC
330);
331
332/*==============================================================*/
333/* Index: Relationship_7_FK */
334/*==============================================================*/
335create index Relationship_7_FK on Poszkodowani (
336IdPacjenta ASC
337);
338
339/*==============================================================*/
340/* Index: Relationship_8_FK */
341/*==============================================================*/
342create index Relationship_8_FK on Poszkodowani (
343IdKodu ASC
344);
345
346/*==============================================================*/
347/* Index: Relationship_9_FK */
348/*==============================================================*/
349create index Relationship_9_FK on Poszkodowani (
350IdSzpitala ASC
351);
352
353/*==============================================================*/
354/* Table: Pracownicy */
355/*==============================================================*/
356create table Pracownicy
357(
358 IdPracownika integer not null,
359 Imie long varchar null,
360 Nazwisko long varchar null,
361 NrDomu long varchar null,
362 NrMieszkania long varchar null,
363 KodPocztowy long varchar null,
364 Poczta long varchar null,
365 PESEL integer null,
366 DataUrodzenia date null,
367 MiejsceUrodzenia long varchar null,
368 "E-mail" long varchar null,
369 Telefon integer null,
370 Zawod long varchar null,
371 constraint PK_PRACOWNICY primary key (IdPracownika)
372);
373
374/*==============================================================*/
375/* Index: Pracownicy_PK */
376/*==============================================================*/
377create unique index Pracownicy_PK on Pracownicy (
378IdPracownika ASC
379);
380
381/*==============================================================*/
382/* Table: Procedury */
383/*==============================================================*/
384create table Procedury
385(
386 IdProcedury integer not null,
387 Opis long varchar null,
388 constraint PK_PROCEDURY primary key (IdProcedury)
389);
390
391/*==============================================================*/
392/* Index: Procedury_PK */
393/*==============================================================*/
394create unique index Procedury_PK on Procedury (
395IdProcedury ASC
396);
397
398/*==============================================================*/
399/* Table: Szpitale */
400/*==============================================================*/
401create table Szpitale
402(
403 IdSzpitala integer not null,
404 Nazwa long varchar null,
405 NrDomu long varchar null,
406 KodPocztowy long varchar null,
407 Poczta long varchar null,
408 Telefon integer null,
409 Miasto long varchar null,
410 Ulica long varchar null,
411 constraint PK_SZPITALE primary key (IdSzpitala)
412);
413
414/*==============================================================*/
415/* Index: Szpitale_PK */
416/*==============================================================*/
417create unique index Szpitale_PK on Szpitale (
418IdSzpitala ASC
419);
420
421/*==============================================================*/
422/* Table: Ulice */
423/*==============================================================*/
424create table Ulice
425(
426 IdUlicy integer not null,
427 NazwaUlicy long varchar null,
428 IdStacji integer null,
429 IdMiejscowosci integer null,
430 constraint PK_ULICE primary key clustered (IdUlicy)
431);
432
433/*==============================================================*/
434/* Index: Ulice_PK */
435/*==============================================================*/
436create unique clustered index Ulice_PK on Ulice (
437IdUlicy ASC
438);
439
440/*==============================================================*/
441/* Index: Relationship_1_FK */
442/*==============================================================*/
443create index Relationship_1_FK on Ulice (
444IdStacji ASC
445);
446
447/*==============================================================*/
448/* Index: Relationship_16_FK */
449/*==============================================================*/
450create index Relationship_16_FK on Ulice (
451IdMiejscowosci ASC
452);
453
454/*==============================================================*/
455/* Table: Wezwania */
456/*==============================================================*/
457create table Wezwania
458(
459 IdWezwania integer not null,
460 IdZgloszenia integer null,
461 constraint PK_WEZWANIA primary key (IdWezwania)
462);
463
464/*==============================================================*/
465/* Index: Wezwania_PK */
466/*==============================================================*/
467create unique index Wezwania_PK on Wezwania (
468IdWezwania ASC
469);
470
471/*==============================================================*/
472/* Index: Relationship_11_FK */
473/*==============================================================*/
474create index Relationship_11_FK on Wezwania (
475IdZgloszenia ASC
476);
477
478/*==============================================================*/
479/* Table: "Wykonane procedury" */
480/*==============================================================*/
481create table "Wykonane procedury"
482(
483 IdWezwania integer not null,
484 IdProcedury integer not null,
485 constraint "PK_WYKONANE PROCEDURY" primary key (IdWezwania, IdProcedury)
486);
487
488/*==============================================================*/
489/* Index: "Wykonane procedury_PK" */
490/*==============================================================*/
491create unique index "Wykonane procedury_PK" on "Wykonane procedury" (
492IdWezwania ASC,
493IdProcedury ASC
494);
495
496/*==============================================================*/
497/* Index: Relationship_3_FK */
498/*==============================================================*/
499create index Relationship_3_FK on "Wykonane procedury" (
500IdWezwania ASC
501);
502
503/*==============================================================*/
504/* Index: Relationship_4_FK */
505/*==============================================================*/
506create index Relationship_4_FK on "Wykonane procedury" (
507IdProcedury ASC
508);
509
510/*==============================================================*/
511/* Table: "Zatrudnieni pracownicy" */
512/*==============================================================*/
513create table "Zatrudnieni pracownicy"
514(
515 IdZesp integer not null,
516 IdPracownika integer not null,
517 DataDolacz date null,
518 DataOpuszczenia date null,
519 constraint "PK_ZATRUDNIENI PRACOWNICY" primary key (IdZesp, IdPracownika)
520);
521
522/*==============================================================*/
523/* Index: "Zatrudnieni pracownicy_PK" */
524/*==============================================================*/
525create unique index "Zatrudnieni pracownicy_PK" on "Zatrudnieni pracownicy" (
526IdZesp ASC,
527IdPracownika ASC
528);
529
530/*==============================================================*/
531/* Index: Relationship_1_FK */
532/*==============================================================*/
533create index Relationship_1_FK on "Zatrudnieni pracownicy" (
534IdZesp ASC
535);
536
537/*==============================================================*/
538/* Index: Relationship_2_FK */
539/*==============================================================*/
540create index Relationship_2_FK on "Zatrudnieni pracownicy" (
541IdPracownika ASC
542);
543
544/*==============================================================*/
545/* Table: "Zespoly do wezwania" */
546/*==============================================================*/
547create table "Zespoly do wezwania"
548(
549 IdZesp integer not null,
550 IdWezwania integer not null,
551 constraint "PK_ZESPOLY DO WEZWANIA" primary key (IdZesp, IdWezwania)
552);
553
554/*==============================================================*/
555/* Index: "Zespoły do wezwania_PK" */
556/*==============================================================*/
557create unique index "Zespoły do wezwania_PK" on "Zespoly do wezwania" (
558IdZesp ASC,
559IdWezwania ASC
560);
561
562/*==============================================================*/
563/* Index: Relationship_10_FK */
564/*==============================================================*/
565create index Relationship_10_FK on "Zespoly do wezwania" (
566IdWezwania ASC
567);
568
569/*==============================================================*/
570/* Index: Relationship_12_FK */
571/*==============================================================*/
572create index Relationship_12_FK on "Zespoly do wezwania" (
573IdZesp ASC
574);
575
576/*==============================================================*/
577/* Table: "Zespoly ratownictwa medycznego" */
578/*==============================================================*/
579create table "Zespoly ratownictwa medycznego"
580(
581 IdZesp integer not null,
582 IdStacji integer null,
583 IdKaretki integer null,
584 constraint "PK_ZESPOLY RATOWNICTWA MEDYCZN" primary key (IdZesp)
585);
586
587/*==============================================================*/
588/* Index: "Zespoły ratownictwa medycznego_PK" */
589/*==============================================================*/
590create unique index "Zespoły ratownictwa medycznego_PK" on "Zespoly ratownictwa medycznego" (
591IdZesp ASC
592);
593
594/*==============================================================*/
595/* Index: Relationship_13_FK */
596/*==============================================================*/
597create index Relationship_13_FK on "Zespoly ratownictwa medycznego" (
598IdKaretki ASC
599);
600
601/*==============================================================*/
602/* Index: Relationship_14_FK */
603/*==============================================================*/
604create index Relationship_14_FK on "Zespoly ratownictwa medycznego" (
605IdStacji ASC
606);
607
608/*==============================================================*/
609/* Table: Zgloszenia */
610/*==============================================================*/
611create table Zgloszenia
612(
613 IdZgloszenia integer not null,
614 Data date null,
615 GodzPrzyjecia time null,
616 GodzWyslania time null,
617 IdDyspozytora integer null,
618 constraint PK_ZGLOSZENIA primary key (IdZgloszenia)
619);
620
621/*==============================================================*/
622/* Index: Zgłoszenia_PK */
623/*==============================================================*/
624create unique index Zgłoszenia_PK on Zgloszenia (
625IdZgloszenia ASC
626);
627
628/*==============================================================*/
629/* Index: Relationship_5_FK */
630/*==============================================================*/
631create index Relationship_5_FK on Zgloszenia (
632IdDyspozytora ASC
633);
634
635alter table Poszkodowani
636 add constraint FK_POSZKODO_RELATIONS_WEZWANIA foreign key (IdWezwania)
637 references Wezwania (IdWezwania)
638 on update restrict
639 on delete restrict;
640
641alter table Poszkodowani
642 add constraint FK_POSZKODO_RELATIONS_PACJENCI foreign key (IdPacjenta)
643 references Pacjenci (IdPacjenta)
644 on update restrict
645 on delete restrict;
646
647alter table Poszkodowani
648 add constraint FK_POSZKODO_RELATIONS_KODY foreign key (IdKodu)
649 references Kody (IdKodu)
650 on update restrict
651 on delete restrict;
652
653alter table Poszkodowani
654 add constraint FK_POSZKODO_RELATIONS_SZPITALE foreign key (IdSzpitala)
655 references Szpitale (IdSzpitala)
656 on update restrict
657 on delete restrict;
658
659alter table Ulice
660 add constraint FK_ULICE_RELATIONS_PODSTACJ foreign key (IdStacji)
661 references Podstacje (IdStacji)
662 on update restrict
663 on delete restrict;
664
665alter table Ulice
666 add constraint FK_ULICE_RELATIONS_MIEJSCOW foreign key (IdMiejscowosci)
667 references Miejscowosci (IdMiejscowosci)
668 on update restrict
669 on delete restrict;
670
671alter table Wezwania
672 add constraint FK_WEZWANIA_RELATIONS_ZGLOSZEN foreign key (IdZgloszenia)
673 references Zgloszenia (IdZgloszenia)
674 on update restrict
675 on delete restrict;
676
677alter table "Wykonane procedury"
678 add constraint FK_WYKONANE_RELATIONS_WEZWANIA foreign key (IdWezwania)
679 references Wezwania (IdWezwania)
680 on update restrict
681 on delete restrict;
682
683alter table "Wykonane procedury"
684 add constraint FK_WYKONANE_RELATIONS_PROCEDUR foreign key (IdProcedury)
685 references Procedury (IdProcedury)
686 on update restrict
687 on delete restrict;
688
689alter table "Zatrudnieni pracownicy"
690 add constraint FK_ZATRUDNI_RELATIONS_ZESPOLY foreign key (IdZesp)
691 references "Zespoly ratownictwa medycznego" (IdZesp)
692 on update restrict
693 on delete restrict;
694
695alter table "Zatrudnieni pracownicy"
696 add constraint FK_ZATRUDNI_RELATIONS_PRACOWNI foreign key (IdPracownika)
697 references Pracownicy (IdPracownika)
698 on update restrict
699 on delete restrict;
700
701alter table "Zespoly do wezwania"
702 add constraint "FK_ZESPOLY _RELATIONS_WEZWANIA" foreign key (IdWezwania)
703 references Wezwania (IdWezwania)
704 on update restrict
705 on delete restrict;
706
707alter table "Zespoly do wezwania"
708 add constraint "FK_ZESPOLY _RELATIONS_ZESPOLY" foreign key (IdZesp)
709 references "Zespoly ratownictwa medycznego" (IdZesp)
710 on update restrict
711 on delete restrict;
712
713alter table "Zespoly ratownictwa medycznego"
714 add constraint "FK_ZESPOLY _RELATIONS_KARETKI" foreign key (IdKaretki)
715 references Karetki (IdKaretki)
716 on update restrict
717 on delete restrict;
718
719alter table "Zespoly ratownictwa medycznego"
720 add constraint "FK_ZESPOLY _RELATIONS_PODSTACJ" foreign key (IdStacji)
721 references Podstacje (IdStacji)
722 on update restrict
723 on delete restrict;
724
725alter table Zgloszenia
726 add constraint FK_ZGLOSZEN_RELATIONS_DYSPOZYT foreign key (IdDyspozytora)
727 references Dyspozytorzy (IdDyspozytora)
728 on update restrict
729 on delete restrict;