-- Drop tables
-- Create tables
CREATE TABLE uir_adr_posta (
psc NUMERIC(5) NOT NULL,
nazev VARCHAR(48) NOT NULL,
zkratka VARCHAR(16) NOT NULL,
stav NUMERIC(1) NOT NULL,
vznik_dne DATE,
vznik_info VARCHAR(254),
zanik_dne DATE,
zanik_info VARCHAR(254)
);
CREATE TABLE uir_adr_posta_h (
psc NUMERIC(5) NOT NULL,
plati_do DATE NOT NULL,
nazev VARCHAR(48) NOT NULL,
zkratka VARCHAR(16) NOT NULL,
info VARCHAR(254)
);
CREATE TABLE uir_adr_oblast (
oblast_kod NUMERIC(2) NOT NULL,
nuts2 VARCHAR(4) NOT NULL,
nazev VARCHAR(32) NOT NULL,
zkratka VARCHAR(16) NOT NULL,
stav NUMERIC(1) NOT NULL,
vznik_dne DATE,
vznik_info VARCHAR(254),
zanik_dne DATE,
zanik_info VARCHAR(254)
);
CREATE TABLE uir_adr_oblast_h (
oblast_kod NUMERIC(2) NOT NULL,
plati_do DATE NOT NULL,
nuts2 VARCHAR(4) NOT NULL,
nazev VARCHAR(32) NOT NULL,
zkratka VARCHAR(16) NOT NULL,
info VARCHAR(254)
);
CREATE TABLE uir_adr_kraj (
kraj_kod NUMERIC(3) NOT NULL,
nuts3 VARCHAR(5) NOT NULL,
oblast_kod NUMERIC(2) NOT NULL,
nazev VARCHAR(32) NOT NULL,
zkratka VARCHAR(16) NOT NULL,
stav NUMERIC(1) NOT NULL,
vznik_dne DATE,
vznik_info VARCHAR(254),
zanik_dne DATE,
zanik_info VARCHAR(254)
);
CREATE TABLE uir_adr_kraj_h (
kraj_kod NUMERIC(3) NOT NULL,
plati_do DATE NOT NULL,
nuts3 VARCHAR(5) NOT NULL,
oblast_kod NUMERIC(2) NOT NULL,
nazev VARCHAR(32) NOT NULL,
zkratka VARCHAR(16) NOT NULL,
info VARCHAR(254)
);
CREATE TABLE uir_adr_okres (
okres_kod NUMERIC(4) NOT NULL,
nazev VARCHAR(32) NOT NULL,
zkratka VARCHAR(16) NOT NULL,
stav NUMERIC(1) NOT NULL,
vznik_dne DATE,
vznik_info VARCHAR(254),
zanik_dne DATE,
zanik_info VARCHAR(254),
nuts4 VARCHAR(6) NOT NULL,
kraj_kod NUMERIC(3)
);
CREATE TABLE uir_adr_okres_h (
okres_kod NUMERIC(4) NOT NULL,
plati_do DATE NOT NULL,
nazev VARCHAR(32) NOT NULL,
zkratka VARCHAR(16) NOT NULL,
info VARCHAR(254),
nuts4 VARCHAR(6) NOT NULL,
kraj_kod NUMERIC(3)
);
CREATE TABLE uir_adr_orp (
orp_kod NUMERIC(4) NOT NULL,
kodorp_csu NUMERIC(4),
kraj_kod NUMERIC(3) NOT NULL,
nazev VARCHAR(48) NOT NULL,
zkratka VARCHAR(16) NOT NULL,
stav NUMERIC(1) NOT NULL,
vznik_dne DATE,
vznik_info VARCHAR(254),
zanik_dne DATE,
zanik_info VARCHAR(254)
);
CREATE TABLE uir_adr_orp_h (
orp_kod NUMERIC(4) NOT NULL,
plati_do DATE NOT NULL,
kodorp_csu NUMERIC(4),
kraj_kod NUMERIC(3) NOT NULL,
nazev VARCHAR(48) NOT NULL,
zkratka VARCHAR(16) NOT NULL,
info VARCHAR(254)
);
CREATE TABLE uir_adr_pou (
pou_kod NUMERIC(4) NOT NULL,
kodpou_csu NUMERIC(5),
orp_kod NUMERIC(4) NOT NULL,
nazev VARCHAR(48) NOT NULL,
zkratka VARCHAR(16) NOT NULL,
stav NUMERIC(1) NOT NULL,
vznik_dne DATE,
vznik_info VARCHAR(254),
zanik_dne DATE,
zanik_info VARCHAR(254)
);
CREATE TABLE uir_adr_pou_h (
pou_kod NUMERIC(4) NOT NULL,
plati_do DATE NOT NULL,
kodpou_csu NUMERIC(5),
orp_kod NUMERIC(4) NOT NULL,
nazev VARCHAR(48) NOT NULL,
zkratka VARCHAR(16) NOT NULL,
info VARCHAR(254)
);
CREATE TABLE uir_adr_obec (
obec_kod NUMERIC(6) NOT NULL,
okres_kod NUMERIC(4) NOT NULL,
nazev VARCHAR(48) NOT NULL,
zkratka VARCHAR(16) NOT NULL,
stav NUMERIC(1) NOT NULL,
vznik_dne DATE,
vznik_info VARCHAR(254),
zanik_dne DATE,
zanik_info VARCHAR(254),
nuts5 VARCHAR(12) NOT NULL,
pou_kod NUMERIC(4)
);
CREATE TABLE uir_adr_obec_h (
obec_kod NUMERIC(6) NOT NULL,
plati_do DATE NOT NULL,
okres_kod NUMERIC(4) NOT NULL,
nazev VARCHAR(48) NOT NULL,
zkratka VARCHAR(16) NOT NULL,
info VARCHAR(254),
nuts5 VARCHAR(12) NOT NULL,
pou_kod NUMERIC(4)
);
CREATE TABLE uir_adr_pobvod (
pobvod_kod NUMERIC(3) NOT NULL,
obec_kod NUMERIC(6) NOT NULL,
nazev VARCHAR(32) NOT NULL,
zkratka VARCHAR(16) NOT NULL,
stav NUMERIC(1) NOT NULL,
vznik_dne DATE,
vznik_info VARCHAR(254),
zanik_dne DATE,
zanik_info VARCHAR(254)
);
CREATE TABLE uir_adr_pobvod_h (
pobvod_kod NUMERIC(3) NOT NULL,
plati_do DATE NOT NULL,
obec_kod NUMERIC(6) NOT NULL,
nazev VARCHAR(32) NOT NULL,
zkratka VARCHAR(16) NOT NULL,
info VARCHAR(254)
);
CREATE TABLE uir_adr_sobvod (
sobvod_kod NUMERIC(3) NOT NULL,
cislo NUMERIC(2),
obec_kod NUMERIC(6) NOT NULL,
nazev VARCHAR(32) NOT NULL,
zkratka VARCHAR(16) NOT NULL,
stav NUMERIC(1) NOT NULL,
vznik_dne DATE,
vznik_info VARCHAR(254),
zanik_dne DATE,
zanik_info VARCHAR(254)
);
CREATE TABLE uir_adr_sobvod_h (
sobvod_kod NUMERIC(3) NOT NULL,
plati_do DATE NOT NULL,
cislo NUMERIC(2),
obec_kod NUMERIC(6) NOT NULL,
nazev VARCHAR(32) NOT NULL,
zkratka VARCHAR(16) NOT NULL,
info VARCHAR(254)
);
CREATE TABLE uir_adr_nobvod (
nobvod_kod NUMERIC(3) NOT NULL,
nuts4 VARCHAR(6) NOT NULL,
obec_kod NUMERIC(6) NOT NULL,
nazev VARCHAR(32) NOT NULL,
zkratka VARCHAR(16) NOT NULL,
stav NUMERIC(1) NOT NULL,
vznik_dne DATE,
vznik_info VARCHAR(254),
zanik_dne DATE,
zanik_info VARCHAR(254)
);
CREATE TABLE uir_adr_nobvod_h (
nobvod_kod NUMERIC(3) NOT NULL,
plati_do DATE NOT NULL,
nuts4 VARCHAR(6) NOT NULL,
obec_kod NUMERIC(6) NOT NULL,
nazev VARCHAR(32) NOT NULL,
zkratka VARCHAR(16) NOT NULL,
info VARCHAR(254)
);
CREATE TABLE uir_adr_mcast (
mcast_kod NUMERIC(6) NOT NULL,
obec_kod NUMERIC(6) NOT NULL,
pobvod_kod NUMERIC(3),
typ NUMERIC(1) NOT NULL,
nazev VARCHAR(48) NOT NULL,
zkratka VARCHAR(16) NOT NULL,
stav NUMERIC(1) NOT NULL,
vznik_dne DATE,
vznik_info VARCHAR(254),
zanik_dne DATE,
zanik_info VARCHAR(254),
sobvod_kod NUMERIC(3),
nobvod_kod NUMERIC(3)
);
CREATE TABLE uir_adr_mcast_h (
mcast_kod NUMERIC(6) NOT NULL,
plati_do DATE NOT NULL,
obec_kod NUMERIC(6) NOT NULL,
pobvod_kod NUMERIC(3),
typ NUMERIC(1) NOT NULL,
nazev VARCHAR(48) NOT NULL,
zkratka VARCHAR(16) NOT NULL,
info VARCHAR(254),
sobvod_kod NUMERIC(3),
nobvod_kod NUMERIC(3)
);
CREATE TABLE uir_adr_cobce (
cobce_kod NUMERIC(6) NOT NULL,
obec_kod NUMERIC(6) NOT NULL,
nazev VARCHAR(48) NOT NULL,
zkratka VARCHAR(16) NOT NULL,
stav NUMERIC(1) NOT NULL,
vznik_dne DATE,
vznik_info VARCHAR(254),
zanik_dne DATE,
zanik_info VARCHAR(254)
);
CREATE TABLE uir_adr_cobce_h (
cobce_kod NUMERIC(6) NOT NULL,
plati_do DATE NOT NULL,
obec_kod NUMERIC(6) NOT NULL,
nazev VARCHAR(48) NOT NULL,
zkratka VARCHAR(16) NOT NULL,
info VARCHAR(254)
);
CREATE TABLE uir_adr_ulice (
ulice_kod NUMERIC(7) NOT NULL,
obec_kod NUMERIC(6) NOT NULL,
nazev VARCHAR(48) NOT NULL,
zkratka VARCHAR(16) NOT NULL,
stav NUMERIC(1) NOT NULL,
vznik_dne DATE,
vznik_info VARCHAR(254),
zanik_dne DATE,
zanik_info VARCHAR(254)
);
CREATE TABLE uir_adr_ulice_h (
ulice_kod NUMERIC(7) NOT NULL,
plati_do DATE NOT NULL,
obec_kod NUMERIC(6) NOT NULL,
nazev VARCHAR(48) NOT NULL,
zkratka VARCHAR(16) NOT NULL,
info VARCHAR(254)
);
CREATE TABLE uir_adr_objekt (
objekt_kod NUMERIC(9) NOT NULL,
cobce_kod NUMERIC(6) NOT NULL,
cisdom_typ NUMERIC(1) NOT NULL,
cisdom_hod NUMERIC(4) NOT NULL,
stav NUMERIC(1) NOT NULL,
vznik_dne DATE,
vznik_info VARCHAR(254),
zanik_dne DATE,
zanik_info VARCHAR(254),
mcast_kod NUMERIC(6),
idob NUMERIC(10)
);
CREATE TABLE uir_adr_objekt_h (
objekt_kod NUMERIC(9) NOT NULL,
plati_do DATE NOT NULL,
cobce_kod NUMERIC(6) NOT NULL,
cisdom_typ NUMERIC(1) NOT NULL,
cisdom_hod NUMERIC(4) NOT NULL,
info VARCHAR(254),
mcast_kod NUMERIC(6)
);
CREATE TABLE uir_adr_adresa (
adresa_kod NUMERIC(9) NOT NULL,
objekt_kod NUMERIC(9) NOT NULL,
ulice_kod NUMERIC(7),
cisor_hod NUMERIC(3),
cisor_pis VARCHAR(1),
psc NUMERIC(5) NOT NULL,
stav NUMERIC(1) NOT NULL,
vznik_dne DATE,
vznik_info VARCHAR(254),
zanik_dne DATE,
zanik_info VARCHAR(254),
pcd NUMERIC(10),
x NUMERIC(8),
y NUMERIC(7)
);
CREATE TABLE uir_adr_adresa_h (
adresa_kod NUMERIC(9) NOT NULL,
plati_do DATE NOT NULL,
objekt_kod NUMERIC(9) NOT NULL,
ulice_kod NUMERIC(7),
cisor_hod NUMERIC(3),
cisor_pis VARCHAR(1),
psc NUMERIC(5) NOT NULL,
info VARCHAR(254)
);
CREATE TABLE uir_adr_obec_d (
obec_kod NUMERIC(6) NOT NULL,
adresa_kod NUMERIC(9) NOT NULL,
jmeno VARCHAR(40),
telefon VARCHAR(40),
e_mail VARCHAR(50)
);
CREATE TABLE uir_adr_vazba (
vazba_id NUMERIC(7) NOT NULL,
mcast_kod NUMERIC(6),
cobce_kod NUMERIC(6) NOT NULL,
ulice_kod NUMERIC(7),
psc NUMERIC(5) NOT NULL
);
CREATE TABLE uir_adr_cob_prev (
kodcob NUMERIC(6) NOT NULL,
plati_od DATE NOT NULL,
plati_do DATE NOT NULL,
cobce_kod NUMERIC(6) NOT NULL,
mcast_kod NUMERIC(6)
);
CREATE TABLE uir_adr_verze (
ver_cislo NUMERIC(5) NOT NULL,
ver_zsj VARCHAR(5),
cas_uzav TIMESTAMP
);
CREATE TABLE uir_adr_zmen_zaz (
zmena_id NUMERIC(9) NOT NULL,
ver_cislo NUMERIC(5) NOT NULL,
tabulka NUMERIC(2) NOT NULL,
prim_klic VARCHAR(21) NOT NULL,
operace NUMERIC(1) NOT NULL,
dokum VARCHAR(10) NOT NULL
);
CREATE TABLE uir_adr_zmen_atr (
zmena_id NUMERIC(9) NOT NULL,
pozice NUMERIC(2) NOT NULL,
hodnota VARCHAR(254)
);
CREATE TABLE uir_adr_stav_db (
verze_db_1 NUMERIC(2) NOT NULL,
verze_db_2 NUMERIC(2) NOT NULL
);
-- Set right encoding for csv
\encoding WIN1250
-- Load tables data from csv
\copy uir_adr_adresa from 'adresa.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_adresa_h from 'adresa_h.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_cob_prev from 'cob_prev.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_cobce from 'cobce.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_cobce_h from 'cobce_h.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_kraj from 'kraj.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_kraj_h from 'kraj_h.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_mcast from 'mcast.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_mcast_h from 'mcast_h.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_nobvod from 'nobvod.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_nobvod_h from 'nobvod_h.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_obec from 'obec.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_obec_d from 'obec_d.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_obec_h from 'obec_h.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_objekt from 'objekt.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_objekt_h from 'objekt_h.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_oblast from 'oblast.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_oblast_h from 'oblast_h.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_okres from 'okres.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_okres_h from 'okres_h.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_orp from 'orp.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_orp_h from 'orp_h.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_pobvod from 'pobvod.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_pobvod_h from 'pobvod_h.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_posta from 'posta.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_posta_h from 'posta_h.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_pou from 'pou.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_pou_h from 'pou_h.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_sobvod from 'sobvod.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_sobvod_h from 'sobvod_h.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_stav_db from 'stav_db.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_ulice from 'ulice.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_ulice_h from 'ulice_h.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_vazba from 'vazba.csv' delimiter as ',' csv quote as ''''
\copy uir_adr_verze from 'verze.csv' delimiter as ',' csv quote as ''''
-- \copy uir_adr_zmen_atr from 'zmen_atr.csv' delimiter as ',' csv quote as ''''
-- \copy uir_adr_zmen_zaz from 'zmen_zaz.csv' delimiter as ',' csv quote as ''''
-- Portax extensions
ALTER TABLE uir_adr_verze add column cas_importu TIMESTAMP;
DELETE FROM uir_adr_verze WHERE cas_uzav IS NULL;
UPDATE uir_adr_verze set cas_importu=NOW();
-- Primary keys:
ALTER TABLE uir_adr_posta ADD CONSTRAINT xpkposta  PRIMARY KEY (psc);
ALTER TABLE uir_adr_posta_h ADD CONSTRAINT xpkposta_h  PRIMARY KEY (psc,plati_do);
ALTER TABLE uir_adr_oblast ADD CONSTRAINT xpkoblast  PRIMARY KEY (oblast_kod);
ALTER TABLE uir_adr_oblast_h ADD CONSTRAINT xpkoblast_h  PRIMARY KEY (oblast_kod,plati_do);
ALTER TABLE uir_adr_kraj ADD CONSTRAINT xpkkraj  PRIMARY KEY (kraj_kod);
ALTER TABLE uir_adr_kraj_h ADD CONSTRAINT xpkkraj_h  PRIMARY KEY (kraj_kod,plati_do);
ALTER TABLE uir_adr_okres ADD CONSTRAINT xpkokres  PRIMARY KEY (okres_kod);
ALTER TABLE uir_adr_okres_h ADD CONSTRAINT xpkokres_h  PRIMARY KEY (okres_kod,plati_do);
ALTER TABLE uir_adr_orp ADD CONSTRAINT xpkorp  PRIMARY KEY (orp_kod);
ALTER TABLE uir_adr_orp_h ADD CONSTRAINT xpkorp_h  PRIMARY KEY (orp_kod,plati_do);
ALTER TABLE uir_adr_pou ADD CONSTRAINT xpkpou  PRIMARY KEY (pou_kod);
ALTER TABLE uir_adr_pou_h ADD CONSTRAINT xpkpou_h  PRIMARY KEY (pou_kod,plati_do);
ALTER TABLE uir_adr_obec ADD CONSTRAINT xpkobec  PRIMARY KEY (obec_kod);
ALTER TABLE uir_adr_obec_h ADD CONSTRAINT xpkobec_h  PRIMARY KEY (obec_kod,plati_do);
ALTER TABLE uir_adr_pobvod ADD CONSTRAINT xpkpobvod  PRIMARY KEY (pobvod_kod);
ALTER TABLE uir_adr_pobvod_h ADD CONSTRAINT xpkpobvod_h  PRIMARY KEY (pobvod_kod,plati_do);
ALTER TABLE uir_adr_sobvod ADD CONSTRAINT xpksobvod  PRIMARY KEY (sobvod_kod);
ALTER TABLE uir_adr_sobvod_h ADD CONSTRAINT xpksobvod_h  PRIMARY KEY (sobvod_kod,plati_do);
ALTER TABLE uir_adr_nobvod ADD CONSTRAINT xpknobvod  PRIMARY KEY (nobvod_kod);
ALTER TABLE uir_adr_nobvod_h ADD CONSTRAINT xpknobvod_h  PRIMARY KEY (nobvod_kod,plati_do);
ALTER TABLE uir_adr_mcast ADD CONSTRAINT xpkmcast  PRIMARY KEY (mcast_kod);
ALTER TABLE uir_adr_mcast_h ADD CONSTRAINT xpkmcast_h  PRIMARY KEY (mcast_kod,plati_do);
ALTER TABLE uir_adr_cobce ADD CONSTRAINT xpkcobce  PRIMARY KEY (cobce_kod);
ALTER TABLE uir_adr_cobce_h ADD CONSTRAINT xpkcobce_h  PRIMARY KEY (cobce_kod,plati_do);
ALTER TABLE uir_adr_ulice ADD CONSTRAINT xpkulice  PRIMARY KEY (ulice_kod);
ALTER TABLE uir_adr_ulice_h ADD CONSTRAINT xpkulice_h  PRIMARY KEY (ulice_kod,plati_do);
ALTER TABLE uir_adr_objekt ADD CONSTRAINT xpkobjekt  PRIMARY KEY (objekt_kod);
ALTER TABLE uir_adr_objekt_h ADD CONSTRAINT xpkobjekt_h  PRIMARY KEY (objekt_kod,plati_do);
ALTER TABLE uir_adr_adresa ADD CONSTRAINT xpkadresa  PRIMARY KEY (adresa_kod);
ALTER TABLE uir_adr_adresa_h ADD CONSTRAINT xpkadresa_h  PRIMARY KEY (adresa_kod,plati_do);
ALTER TABLE uir_adr_obec_d ADD CONSTRAINT xpkobec_d  PRIMARY KEY (obec_kod);
ALTER TABLE uir_adr_vazba ADD CONSTRAINT xpkvazba  PRIMARY KEY (vazba_id);
ALTER TABLE uir_adr_cob_prev ADD CONSTRAINT xpkcob_prev  PRIMARY KEY (kodcob,plati_od);
ALTER TABLE uir_adr_verze ADD CONSTRAINT xpkverze  PRIMARY KEY (ver_cislo);
ALTER TABLE uir_adr_zmen_zaz ADD CONSTRAINT xpkzmen_zaz  PRIMARY KEY (zmena_id);
ALTER TABLE uir_adr_zmen_atr ADD CONSTRAINT xpkzmen_atr  PRIMARY KEY (zmena_id,pozice);
-- Unique keys:
ALTER TABLE uir_adr_vazba ADD CONSTRAINT xak1vazba UNIQUE (cobce_kod, psc, ulice_kod, mcast_kod);
ALTER TABLE uir_adr_cob_prev ADD CONSTRAINT xak1cob_prev UNIQUE (cobce_kod, mcast_kod, plati_od);
ALTER TABLE uir_adr_zmen_zaz ADD CONSTRAINT xak1zmen_zaz UNIQUE (tabulka, prim_klic, ver_cislo);
-- Foreign keys:
ALTER TABLE uir_adr_posta_h ADD CONSTRAINT posta_posta_h FOREIGN KEY (psc) REFERENCES uir_adr_posta;
ALTER TABLE uir_adr_oblast_h ADD CONSTRAINT oblast_oblast_h FOREIGN KEY (oblast_kod) REFERENCES uir_adr_oblast;
ALTER TABLE uir_adr_kraj ADD CONSTRAINT oblast_kraj FOREIGN KEY (oblast_kod) REFERENCES uir_adr_oblast;
ALTER TABLE uir_adr_kraj_h ADD CONSTRAINT kraj_kraj_h FOREIGN KEY (kraj_kod) REFERENCES uir_adr_kraj;
ALTER TABLE uir_adr_kraj_h ADD CONSTRAINT oblast_kraj_h FOREIGN KEY (oblast_kod) REFERENCES uir_adr_oblast;
ALTER TABLE uir_adr_okres ADD CONSTRAINT kraj_okres FOREIGN KEY (kraj_kod) REFERENCES uir_adr_kraj;
ALTER TABLE uir_adr_okres_h ADD CONSTRAINT okres_okres_h FOREIGN KEY (okres_kod) REFERENCES uir_adr_okres;
ALTER TABLE uir_adr_okres_h ADD CONSTRAINT kraj_okres_h FOREIGN KEY (kraj_kod) REFERENCES uir_adr_kraj;
ALTER TABLE uir_adr_orp ADD CONSTRAINT kraj_orp FOREIGN KEY (kraj_kod) REFERENCES uir_adr_kraj;
ALTER TABLE uir_adr_orp_h ADD CONSTRAINT orp_orp_h FOREIGN KEY (orp_kod) REFERENCES uir_adr_orp;
ALTER TABLE uir_adr_orp_h ADD CONSTRAINT kraj_orp_h FOREIGN KEY (kraj_kod) REFERENCES uir_adr_kraj;
ALTER TABLE uir_adr_pou ADD CONSTRAINT orp_pou FOREIGN KEY (orp_kod) REFERENCES uir_adr_orp;
ALTER TABLE uir_adr_pou_h ADD CONSTRAINT pou_pou_h FOREIGN KEY (pou_kod) REFERENCES uir_adr_pou;
ALTER TABLE uir_adr_pou_h ADD CONSTRAINT orp_pou_h FOREIGN KEY (orp_kod) REFERENCES uir_adr_orp;
ALTER TABLE uir_adr_obec ADD CONSTRAINT okres_obec FOREIGN KEY (okres_kod) REFERENCES uir_adr_okres;
ALTER TABLE uir_adr_obec ADD CONSTRAINT pou_obec FOREIGN KEY (pou_kod) REFERENCES uir_adr_pou;
ALTER TABLE uir_adr_obec_h ADD CONSTRAINT obec_obec_h FOREIGN KEY (obec_kod) REFERENCES uir_adr_obec;
ALTER TABLE uir_adr_obec_h ADD CONSTRAINT okres_obec_h FOREIGN KEY (okres_kod) REFERENCES uir_adr_okres;
ALTER TABLE uir_adr_obec_h ADD CONSTRAINT pou_obec_h FOREIGN KEY (pou_kod) REFERENCES uir_adr_pou;
ALTER TABLE uir_adr_pobvod ADD CONSTRAINT obec_pobvod FOREIGN KEY (obec_kod) REFERENCES uir_adr_obec;
ALTER TABLE uir_adr_pobvod_h ADD CONSTRAINT pobvod_pobvod_h FOREIGN KEY (pobvod_kod) REFERENCES uir_adr_pobvod;
ALTER TABLE uir_adr_pobvod_h ADD CONSTRAINT obec_pobvod_h FOREIGN KEY (obec_kod) REFERENCES uir_adr_obec;
ALTER TABLE uir_adr_sobvod ADD CONSTRAINT obec_sobvod FOREIGN KEY (obec_kod) REFERENCES uir_adr_obec;
ALTER TABLE uir_adr_sobvod_h ADD CONSTRAINT sobvod_sobvod_h FOREIGN KEY (sobvod_kod) REFERENCES uir_adr_sobvod;
ALTER TABLE uir_adr_sobvod_h ADD CONSTRAINT obec_sobvod_h FOREIGN KEY (obec_kod) REFERENCES uir_adr_obec;
ALTER TABLE uir_adr_nobvod ADD CONSTRAINT obec_nobvod FOREIGN KEY (obec_kod) REFERENCES uir_adr_obec;
ALTER TABLE uir_adr_nobvod_h ADD CONSTRAINT nobvod_nobvod_h FOREIGN KEY (nobvod_kod) REFERENCES uir_adr_nobvod;
ALTER TABLE uir_adr_nobvod_h ADD CONSTRAINT obec_nobvod_h FOREIGN KEY (obec_kod) REFERENCES uir_adr_obec;
ALTER TABLE uir_adr_mcast ADD CONSTRAINT obec_mcast FOREIGN KEY (obec_kod) REFERENCES uir_adr_obec;
ALTER TABLE uir_adr_mcast ADD CONSTRAINT pobvod_mcast FOREIGN KEY (pobvod_kod) REFERENCES uir_adr_pobvod;
ALTER TABLE uir_adr_mcast ADD CONSTRAINT sobvod_mcast FOREIGN KEY (sobvod_kod) REFERENCES uir_adr_sobvod;
ALTER TABLE uir_adr_mcast ADD CONSTRAINT nobvod_mcast FOREIGN KEY (nobvod_kod) REFERENCES uir_adr_nobvod;
ALTER TABLE uir_adr_mcast_h ADD CONSTRAINT mcast_mcast_h FOREIGN KEY (mcast_kod) REFERENCES uir_adr_mcast;
ALTER TABLE uir_adr_mcast_h ADD CONSTRAINT obec_mcast_h FOREIGN KEY (obec_kod) REFERENCES uir_adr_obec;
ALTER TABLE uir_adr_mcast_h ADD CONSTRAINT pobvod_mcast_h FOREIGN KEY (pobvod_kod) REFERENCES uir_adr_pobvod;
ALTER TABLE uir_adr_mcast_h ADD CONSTRAINT sobvod_mcast_h FOREIGN KEY (sobvod_kod) REFERENCES uir_adr_sobvod;
ALTER TABLE uir_adr_mcast_h ADD CONSTRAINT nobvod_mcast_h FOREIGN KEY (nobvod_kod) REFERENCES uir_adr_nobvod;
ALTER TABLE uir_adr_cobce ADD CONSTRAINT obec_cobce FOREIGN KEY (obec_kod) REFERENCES uir_adr_obec;
ALTER TABLE uir_adr_cobce_h ADD CONSTRAINT cobce_cobce_h FOREIGN KEY (cobce_kod) REFERENCES uir_adr_cobce;
ALTER TABLE uir_adr_cobce_h ADD CONSTRAINT obec_cobce_h FOREIGN KEY (obec_kod) REFERENCES uir_adr_obec;
ALTER TABLE uir_adr_ulice ADD CONSTRAINT obec_ulice FOREIGN KEY (obec_kod) REFERENCES uir_adr_obec;
ALTER TABLE uir_adr_ulice_h ADD CONSTRAINT ulice_ulice_h FOREIGN KEY (ulice_kod) REFERENCES uir_adr_ulice;
ALTER TABLE uir_adr_ulice_h ADD CONSTRAINT obec_ulice_h FOREIGN KEY (obec_kod) REFERENCES uir_adr_obec;
ALTER TABLE uir_adr_objekt ADD CONSTRAINT cobce_objekt FOREIGN KEY (cobce_kod) REFERENCES uir_adr_cobce;
ALTER TABLE uir_adr_objekt ADD CONSTRAINT mcast_objekt FOREIGN KEY (mcast_kod) REFERENCES uir_adr_mcast;
ALTER TABLE uir_adr_objekt_h ADD CONSTRAINT objekt_objekt_h FOREIGN KEY (objekt_kod) REFERENCES uir_adr_objekt;
ALTER TABLE uir_adr_objekt_h ADD CONSTRAINT cobce_objekt_h FOREIGN KEY (cobce_kod) REFERENCES uir_adr_cobce;
ALTER TABLE uir_adr_objekt_h ADD CONSTRAINT mcast_objekt_h FOREIGN KEY (mcast_kod) REFERENCES uir_adr_mcast;
ALTER TABLE uir_adr_adresa ADD CONSTRAINT objekt_adresa FOREIGN KEY (objekt_kod) REFERENCES uir_adr_objekt;
ALTER TABLE uir_adr_adresa ADD CONSTRAINT ulice_adresa FOREIGN KEY (ulice_kod) REFERENCES uir_adr_ulice;
ALTER TABLE uir_adr_adresa ADD CONSTRAINT posta_adresa FOREIGN KEY (psc) REFERENCES uir_adr_posta;
ALTER TABLE uir_adr_adresa_h ADD CONSTRAINT adresa_adresa_h FOREIGN KEY (adresa_kod) REFERENCES uir_adr_adresa;
ALTER TABLE uir_adr_adresa_h ADD CONSTRAINT objekt_adresa_h FOREIGN KEY (objekt_kod) REFERENCES uir_adr_objekt;
ALTER TABLE uir_adr_adresa_h ADD CONSTRAINT ulice_adresa_h FOREIGN KEY (ulice_kod) REFERENCES uir_adr_ulice;
ALTER TABLE uir_adr_adresa_h ADD CONSTRAINT posta_adresa_h FOREIGN KEY (psc) REFERENCES uir_adr_posta;
ALTER TABLE uir_adr_obec_d ADD CONSTRAINT obec_obec_d FOREIGN KEY (obec_kod) REFERENCES uir_adr_obec;
ALTER TABLE uir_adr_obec_d ADD CONSTRAINT adresa_obec_d FOREIGN KEY (adresa_kod) REFERENCES uir_adr_adresa;
ALTER TABLE uir_adr_vazba ADD CONSTRAINT mcast_vazba FOREIGN KEY (mcast_kod) REFERENCES uir_adr_mcast;
ALTER TABLE uir_adr_vazba ADD CONSTRAINT cobce_vazba FOREIGN KEY (cobce_kod) REFERENCES uir_adr_cobce;
ALTER TABLE uir_adr_vazba ADD CONSTRAINT ulice_vazba FOREIGN KEY (ulice_kod) REFERENCES uir_adr_ulice;
ALTER TABLE uir_adr_vazba ADD CONSTRAINT posta_vazba FOREIGN KEY (psc) REFERENCES uir_adr_posta;
ALTER TABLE uir_adr_cob_prev ADD CONSTRAINT cobce_cob_prev FOREIGN KEY (cobce_kod) REFERENCES uir_adr_cobce;
ALTER TABLE uir_adr_cob_prev ADD CONSTRAINT mcast_cob_prev FOREIGN KEY (mcast_kod) REFERENCES uir_adr_mcast;
ALTER TABLE uir_adr_zmen_zaz ADD CONSTRAINT verze_zmen_zaz FOREIGN KEY (ver_cislo) REFERENCES uir_adr_verze;
ALTER TABLE uir_adr_zmen_atr ADD CONSTRAINT zmen_zaz_zmen_atr FOREIGN KEY (zmena_id) REFERENCES uir_adr_zmen_zaz;
