· 8 years ago · Dec 11, 2017, 10:14 PM
1drop table if exists kuv_organizacia;
2drop table if exists spolocnik;
3drop table if exists konatel;
4drop table if exists kuv;
5drop table if exists organizacia;
6drop table if exists faktura;
7drop table if exists odoberatel;
8
9/* Duplikatne zaznamy tu nateraz ignorujeme */
10create table spolocnik (
11 ID integer primary key,
12 meno varchar(30) not null,
13 sidlo varchar(40),
14 ICO integer not null,
15 foreign key (ICO) references organizacia(ICO)
16);
17
18create table konatel (
19 ID integer primary key,
20 meno varchar(40) not null,
21 sidlo varchar(40),
22 ICO integer not null,
23 foreign key (ICO) references organizacia(ICO)
24);
25
26create table organizacia (
27 ICO integer primary key,
28 nazov varchar(40) not null,
29 /* Tieto 3 atributy sa ziskaju az pri parsovani ORSR, najprv sa naplni tabulka faktur,
30 a tam treba vediet pred nastavenim cudzieho kluca aby sa odkazoval do tejto tabulky
31 zadat aspon ICO a nazov organizacie. */
32 sidlo varchar(40),
33 den_zapisu integer,
34 pravna_forma varchar(20)
35);
36
37create table kuv (
38 ID integer primary key,
39 meno varchar(30) not null,
40 adresa varchar(30) not null
41);
42
43create table kuv_organizacia (
44 ID_kuv integer,
45 ICO_organizacia integer,
46 foreign key (ID_kuv) references kuv(ID),
47 foreign key (ICO_organizacia) references organizacia(ICO),
48 primary key (ID_kuv, ICO_organizacia)
49);
50
51
52-- Prislusne okresne mesta a mestske casti Kosic
53
54
55
56CREATE TABLE odoberatel (
57 ICO integer primary key,
58 nazov_obce varchar(30) not null,
59 ulica varchar(30),
60 cislo integer,
61 psc integer
62);
63
64INSERT INTO odoberatel (ICO, nazov_obce, ulica, cislo, psc) values
65 (00691011, 'Šebastovce', 'Podbeľová', 1, 04017),
66 (00690937, 'Staré Mesto', 'Hviezdoslavova', 7, 04001),
67 (00325490, 'Michalovce', 'Nám. osloboditeľov', 30, 07101)
68;
69
70
71create table faktura (
72 ID integer primary key,
73 suma_DPH integer not null,
74 predmet varchar(300) not null,
75 datum date not null,
76 ICO_organizacia integer,
77 ID_subjekt integer,
78 ICO_odoberatel integer not null,
79 foreign key (ICO_organizacia) references organizacia(ICO),
80 foreign key (ICO_odoberatel) references odoberatel(ICO)
81);
82
83
84COMMIT;