DROP
Table
Pohon Cascade
Constraints
;
DROP
Table
Lokace Cascade
Constraints
;
DROP
Table
Smena Cascade
Constraints
;
DROP
Table
Pracovnik Cascade
Constraints
;
DROP
Table
Strojvudce Cascade
Constraints
;
DROP
Table
Posunovac Cascade
Constraints
;
DROP
Table
Pokladni Cascade
Constraints
;
DROP
Table
Zamestnani Cascade
Constraints
;
DROP
Table
Skupina_pracovist Cascade
Constraints
;
DROP
Table
Razeni Cascade
Constraints
;
DROP
Table
Zastavka Cascade
Constraints
;
DROP
Table
Typ_vuz Cascade
Constraints
;
DROP
Table
Typ_vagon Cascade
Constraints
;
DROP
Table
Typ_lokomotiva Cascade
Constraints
;
DROP
Table
Obecny Cascade
Constraints
;
DROP
Table
Lokomotiva Cascade
Constraints
;
DROP
Table
Vagon Cascade
Constraints
;
DROP
Table
Stanice Cascade
Constraints
;
DROP
Table
Vuz Cascade
Constraints
;
DROP
Table
Trasa Cascade
Constraints
;
DROP
Table
Skupina_pracovniku Cascade
Constraints
;
DROP
Table
Opravneni Cascade
Constraints
;
DROP
Table
Spoj Cascade
Constraints
;
DROP
Table
Pracoviste Cascade
Constraints
;
DROP
Table
Jizdenka Cascade
Constraints
;
DROP
Table
Vyhybka Cascade
Constraints
;
CREATE
Table
Pohon (
nasobnost Integer
NULL
,
Lokomotiva_Vuz_id_vuz Integer
NOT
NULL
,
Spoj_id_spoj Integer
NOT
NULL
,
Constraint
PK_Pohon Primary
Key
(Lokomotiva_Vuz_id_vuz, Spoj_id_spoj)
);
CREATE
Table
Lokace (
osada VarChar2
(255) NULL
,
souradnice_z Float NOT
NULL
,
souradnice_x Float NOT
NULL
,
souradnice_y Float NOT
NULL
,
id_lokace Integer
NOT
NULL
,
Constraint
PK_Lokace Primary
Key
(id_lokace)
);
CREATE
Table
Smena (
cislo_smeny Integer
NOT
NULL
,
od Date
NOT
NULL
,
do Date
NOT
NULL
,
Constraint
PK_Smena Primary
Key
(cislo_smeny)
);
CREATE
Table
Pracovnik (
jmeno VarChar2
(255) NOT
NULL
,
RC Integer
NOT
NULL
,
Constraint
PK_Pracovnik Primary
Key
(RC)
);
CREATE
Table
Strojvudce (
Pracovnik_RC Integer
NOT
NULL
,
Constraint
PK_Strojvudce Primary
Key
(Pracovnik_RC)
);
CREATE
Table
Posunovac (
Pracovnik_RC Integer
NOT
NULL
,
Constraint
PK_Posunovac Primary
Key
(Pracovnik_RC)
);
CREATE
Table
Pokladni (
Pracovnik_RC Integer
NOT
NULL
,
Constraint
PK_Pokladni Primary
Key
(Pracovnik_RC)
);
CREATE
Table
Zamestnani (
Pracovnik_RC Integer
NOT
NULL
,
Smena_cislo_smeny Integer
NOT
NULL
,
Pracoviste_id_pracoviste Integer
NOT
NULL
,
Constraint
PK_Zamestnani Primary
Key
(Pracovnik_RC, Smena_cislo_smeny, Pracoviste_id_pracoviste)
);
CREATE
Table
Skupina_pracovist (
popis VarChar2
(255) NOT
NULL
,
Constraint
PK_Skupina_pracovist Primary
Key
(popis)
);
CREATE
Table
Razeni (
poradi Integer
NULL
,
kuracky Integer
NULL
,
Spoj_id_spoj Integer
NOT
NULL
,
Vuz_id_vuz Integer
NOT
NULL
,
Constraint
PK_Razeni Primary
Key
(Spoj_id_spoj, Vuz_id_vuz)
);
CREATE
Table
Zastavka (
nastupiste Integer
NULL
,
prijezd Date
NOT
NULL
,
kolej Integer
NOT
NULL
,
odjezd Date
NOT
NULL
,
Spoj_id_spoj Integer
NOT
NULL
,
Stanice_id_stanice Integer
NOT
NULL
,
Constraint
PK_Zastavka Primary
Key
(Spoj_id_spoj, Stanice_id_stanice)
);
CREATE
Table
Typ_vuz (
hmotnost Integer
NOT
NULL
,
pocet_kol Integer
NOT
NULL
,
id_typ_vuz Integer
NOT
NULL
,
Constraint
PK_Typ_vuz Primary
Key
(id_typ_vuz)
);
CREATE
Table
Typ_vagon (
kapacita Integer
NOT
NULL
,
druh Integer
NOT
NULL
,
Typ_vuz_id_typ_vuz Integer
NOT
NULL
,
Constraint
PK_Typ_vagon Primary
Key
(Typ_vuz_id_typ_vuz)
);
CREATE
Table
Typ_lokomotiva (
vykon Integer
NOT
NULL
,
max_tazena_hmotnost Integer
NOT
NULL
,
typ_pohon VarChar2
(255) NOT
NULL
,
Typ_vuz_id_typ_vuz Integer
NOT
NULL
,
Constraint
PK_Typ_lokomotiva Primary
Key
(Typ_vuz_id_typ_vuz)
);
CREATE
Table
Obecny (
skupina_Z_popis VarChar2
(255) NOT
NULL
,
Pracovnik_RC Integer
NOT
NULL
,
Constraint
PK_Obecny Primary
Key
(Pracovnik_RC)
);
CREATE
Table
Lokomotiva (
typ_L_Typ_vuz_id_typ_vuz Integer
NOT
NULL
,
Vuz_id_vuz Integer
NOT
NULL
,
Constraint
PK_Lokomotiva Primary
Key
(Vuz_id_vuz)
);
CREATE
Table
Vagon (
typ_V_Typ_vuz_id_typ_vuz Integer
NOT
NULL
,
Vuz_id_vuz Integer
NOT
NULL
,
Constraint
PK_Vagon Primary
Key
(Vuz_id_vuz)
);
CREATE
Table
Stanice (
nazev VarChar2
(255) NOT
NULL
,
mesto VarChar2
(255) NULL
,
pocet_koleji Integer
NOT
NULL
,
elektrifikace Integer
NULL
,
hala Integer
NULL
,
id_stanice Integer
NOT
NULL
,
umisteni_S_id_lokace Integer
NOT
NULL
,
Constraint
UNQ_Stanice_1 Unique (umisteni_S_id_lokace),
Constraint
PK_Stanice Primary
Key
(id_stanice)
);
CREATE
Table
Vuz (
doma_lokalni_servis Integer
NULL
,
doma_od Date
NOT
NULL
,
id_vuz Integer
NOT
NULL
,
posledni_servis Date
NOT
NULL
,
datum_vyroby Date
NOT
NULL
,
domov_id_stanice Integer
NOT
NULL
,
Constraint
PK_Vuz Primary
Key
(id_vuz)
);
CREATE
Table
Trasa (
kilometry Integer
NOT
NULL
,
svetlost Integer
NULL
,
pocet_tunelu Integer
NULL
,
max_prevyseni Integer
NULL
,
id_trasa Integer
NOT
NULL
,
konec_id_lokace Integer
NOT
NULL
,
zacatek_id_lokace Integer
NOT
NULL
,
Constraint
PK_Trasa Primary
Key
(id_trasa)
);
CREATE
Table
Skupina_pracovniku (
od_pracovist_popis VarChar2
(255) NOT
NULL
,
popis VarChar2
(255) NOT
NULL
,
Constraint
PK_Skupina_pracovniku Primary
Key
(popis)
);
CREATE
Table
Opravneni (
k_rizeni_Typ_vuz_id_typ_vuz Integer
NOT
NULL
,
opravnen_Pracovnik_RC Integer
NOT
NULL
,
Constraint
UNQ_Opravneni_1 Unique (k_rizeni_Typ_vuz_id_typ_vuz, opravnen_Pracovnik_RC)
);
CREATE
Table
Spoj (
zrychleny Integer
NULL
,
osobni_nakladni Integer
NOT
NULL
,
id_spoj Integer
NOT
NULL
,
jede_sobota Integer
NOT
NULL
,
jede_nedele Integer
NOT
NULL
,
jede_svatek Integer
NOT
NULL
,
prijezd_spoj Date
NOT
NULL
,
odjezd_spoj Date
NOT
NULL
,
posun_Pracovnik_RC Integer
NOT
NULL
,
rizeni_Pracovnik_RC Integer
NOT
NULL
,
Constraint
PK_Spoj Primary
Key
(id_spoj)
);
CREATE
Table
Pracoviste (
skupina_P_popis VarChar2
(255) NOT
NULL
,
umisteni_P_id_stanice Integer
NOT
NULL
,
smerovka VarChar2
(255) NULL
,
id_pracoviste Integer
NOT
NULL
,
pocet_mist Integer
NOT
NULL
,
Constraint
PK_Pracoviste Primary
Key
(id_pracoviste)
);
CREATE
Table
Jizdenka (
vydej_kde_id_stanice Integer
NOT
NULL
,
detska Integer
NOT
NULL
,
osoby Integer
NOT
NULL
,
zpatecni Integer
NOT
NULL
,
cena Float NOT
NULL
,
vydej_kdy Date
NOT
NULL
,
id_jizdenka Integer
NOT
NULL
,
cil_id_stanice Integer
NOT
NULL
,
start_id_stanice Integer
NOT
NULL
,
vydej_kym_Pracovnik_RC Integer
NOT
NULL
,
Constraint
PK_Jizdenka Primary
Key
(id_jizdenka)
);
CREATE
Table
Vyhybka (
smer_1_id_stanice Integer
NOT
NULL
,
smer_2_id_stanice Integer
NOT
NULL
,
mechanicka Integer
NULL
,
id_vyhybka Integer
NOT
NULL
,
umisteni_V_id_pracoviste Integer
NOT
NULL
,
Constraint
PK_Vyhybka Primary
Key
(id_vyhybka)
);
ALTER
Table
Pohon add (
Constraint
FK_Pohon_1 Foreign
Key
(Lokomotiva_Vuz_id_vuz) References
Lokomotiva(Vuz_id_vuz),
Constraint
FK_Pohon_2 Foreign
Key
(Spoj_id_spoj) References
Spoj(id_spoj)
);
ALTER
Table
Strojvudce add (
Constraint
FK_Strojvudce_1 Foreign
Key
(Pracovnik_RC) References
Pracovnik(RC)
);
ALTER
Table
Posunovac add (
Constraint
FK_Posunovac_1 Foreign
Key
(Pracovnik_RC) References
Pracovnik(RC)
);
ALTER
Table
Pokladni add (
Constraint
FK_Pokladni_1 Foreign
Key
(Pracovnik_RC) References
Pracovnik(RC)
);
ALTER
Table
Zamestnani add (
Constraint
FK_Zamestnani_1 Foreign
Key
(Pracovnik_RC) References
Pracovnik(RC),
Constraint
FK_Zamestnani_2 Foreign
Key
(Smena_cislo_smeny) References
Smena(cislo_smeny),
Constraint
FK_Zamestnani_3 Foreign
Key
(Pracoviste_id_pracoviste) References
Pracoviste(id_pracoviste)
);
ALTER
Table
Razeni add (
Constraint
FK_Razeni_1 Foreign
Key
(Spoj_id_spoj) References
Spoj(id_spoj),
Constraint
FK_Razeni_2 Foreign
Key
(Vuz_id_vuz) References
Vuz(id_vuz)
);
ALTER
Table
Zastavka add (
Constraint
FK_Zastavka_1 Foreign
Key
(Spoj_id_spoj) References
Spoj(id_spoj),
Constraint
FK_Zastavka_2 Foreign
Key
(Stanice_id_stanice) References
Stanice(id_stanice)
);
ALTER
Table
Typ_vagon add (
Constraint
FK_Typ_vagon_1 Foreign
Key
(Typ_vuz_id_typ_vuz) References
Typ_vuz(id_typ_vuz)
);
ALTER
Table
Typ_lokomotiva add (
Constraint
FK_Typ_lokomotiva_1 Foreign
Key
(Typ_vuz_id_typ_vuz) References
Typ_vuz(id_typ_vuz)
);
ALTER
Table
Obecny add (
Constraint
FK_Obecny_1 Foreign
Key
(Pracovnik_RC) References
Pracovnik(RC),
Constraint
FK_Obecny_2 Foreign
Key
(skupina_Z_popis) References
Skupina_pracovniku(popis)
);
ALTER
Table
Lokomotiva add (
Constraint
FK_Lokomotiva_1 Foreign
Key
(Vuz_id_vuz) References
Vuz(id_vuz),
Constraint
FK_Lokomotiva_2 Foreign
Key
(typ_L_Typ_vuz_id_typ_vuz) References
Typ_lokomotiva(Typ_vuz_id_typ_vuz)
);
ALTER
Table
Vagon add (
Constraint
FK_Vagon_1 Foreign
Key
(Vuz_id_vuz) References
Vuz(id_vuz),
Constraint
FK_Vagon_2 Foreign
Key
(typ_V_Typ_vuz_id_typ_vuz) References
Typ_vagon(Typ_vuz_id_typ_vuz)
);
ALTER
Table
Stanice add (
Constraint
FK_Stanice_1 Foreign
Key
(umisteni_S_id_lokace) References
Lokace(id_lokace)
);
ALTER
Table
Vuz add (
Constraint
FK_Vuz_1 Foreign
Key
(domov_id_stanice) References
Stanice(id_stanice)
);
ALTER
Table
Trasa add (
Constraint
FK_Trasa_1 Foreign
Key
(zacatek_id_lokace) References
Lokace(id_lokace),
Constraint
FK_Trasa_2 Foreign
Key
(konec_id_lokace) References
Lokace(id_lokace)
);
ALTER
Table
Skupina_pracovniku add (
Constraint
FK_Skupina_pracovniku_1 Foreign
Key
(od_pracovist_popis) References
Skupina_pracovist(popis)
);
ALTER
Table
Opravneni add (
Constraint
FK_Opravneni_1 Foreign
Key
(k_rizeni_Typ_vuz_id_typ_vuz) References
Typ_lokomotiva(Typ_vuz_id_typ_vuz),
Constraint
FK_Opravneni_2 Foreign
Key
(opravnen_Pracovnik_RC) References
Strojvudce(Pracovnik_RC)
);
ALTER
Table
Spoj add (
Constraint
FK_Spoj_1 Foreign
Key
(rizeni_Pracovnik_RC) References
Strojvudce(Pracovnik_RC),
Constraint
FK_Spoj_2 Foreign
Key
(posun_Pracovnik_RC) References
Posunovac(Pracovnik_RC)
);
ALTER
Table
Pracoviste add (
Constraint
FK_Pracoviste_1 Foreign
Key
(skupina_P_popis) References
Skupina_pracovist(popis),
Constraint
FK_Pracoviste_2 Foreign
Key
(umisteni_P_id_stanice) References
Stanice(id_stanice)
);
ALTER
Table
Jizdenka add (
Constraint
FK_Jizdenka_1 Foreign
Key
(vydej_kym_Pracovnik_RC) References
Pokladni(Pracovnik_RC),
Constraint
FK_Jizdenka_2 Foreign
Key
(vydej_kde_id_stanice) References
Stanice(id_stanice),
Constraint
FK_Jizdenka_3 Foreign
Key
(start_id_stanice) References
Stanice(id_stanice),
Constraint
FK_Jizdenka_4 Foreign
Key
(cil_id_stanice) References
Stanice(id_stanice)
);
ALTER
Table
Vyhybka add (
Constraint
FK_Vyhybka_1 Foreign
Key
(smer_1_id_stanice) References
Stanice(id_stanice),
Constraint
FK_Vyhybka_2 Foreign
Key
(smer_2_id_stanice) References
Stanice(id_stanice),
Constraint
FK_Vyhybka_3 Foreign
Key
(umisteni_V_id_pracoviste) References
Pracoviste(id_pracoviste)
);