| 1 | create table project.Korisnik(
|
|---|
| 2 | id_korisnik serial primary key,
|
|---|
| 3 | ime_prezime varchar(100) not null,
|
|---|
| 4 | password_korisnik varchar(100) not null,
|
|---|
| 5 | kreiran_na_datum timestamp default now()
|
|---|
| 6 | );
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 | create table project.Kupuvac(
|
|---|
| 10 | id_korisnik serial primary key,
|
|---|
| 11 | mail varchar(100) not null,
|
|---|
| 12 | constraint fk_kupuvac foreign key (id_korisnik) references project.Korisnik (id_korisnik)
|
|---|
| 13 | );
|
|---|
| 14 |
|
|---|
| 15 | create table project.Admin_korisnik(
|
|---|
| 16 | id_korisnik serial primary key,
|
|---|
| 17 | constraint fk_admin foreign key (id_korisnik) references project.Korisnik (id_korisnik)
|
|---|
| 18 | );
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 | create table project.Dostavuvac(
|
|---|
| 23 | id_korisnik serial primary key,
|
|---|
| 24 | constraint fk_dostavuvac foreign key (id_korisnik) references project.Korisnik (id_korisnik)
|
|---|
| 25 | );
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 | create table project.Magacioner(
|
|---|
| 30 | id_korisnik serial primary key,
|
|---|
| 31 | id_magacin serial,
|
|---|
| 32 | constraint fk_magacioner_magacin foreign key(id_magacin) references project.Magacin (id_magacin),
|
|---|
| 33 | constraint fk_magacioner foreign key (id_korisnik) references project.Korisnik (id_korisnik)
|
|---|
| 34 | );
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 | create table project.TelefonskiBroj(
|
|---|
| 38 | id_korisnik serial references project.Kupuvac(id_korisnik),
|
|---|
| 39 | telefonski_broj varchar(50),
|
|---|
| 40 | constraint pk_telefonski_broj_ primary key (id_korisnik,telefonski_broj)
|
|---|
| 41 | );
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 | create table project.Naracka(
|
|---|
| 45 | id_naracka serial primary key,
|
|---|
| 46 | vkupno_suma integer not null,
|
|---|
| 47 | datum date not null,
|
|---|
| 48 | status varchar(50) not null,
|
|---|
| 49 | adresa varchar(100) not null,
|
|---|
| 50 | id_korisnik serial,
|
|---|
| 51 | constraint fk_kupuvac foreign key(id_korisnik) references project.Kupuvac (id_korisnik)
|
|---|
| 52 | );
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 | create table project.Dostava(
|
|---|
| 57 | id_korisnik serial,
|
|---|
| 58 | id_naracka serial,
|
|---|
| 59 | id_dostava serial primary key,
|
|---|
| 60 | datum date not null,
|
|---|
| 61 | status varchar(50) not null,
|
|---|
| 62 | constraint fk_kupuvac foreign key(id_korisnik) references project.Dostavuvac (id_korisnik),
|
|---|
| 63 | constraint fk_naracka foreign key (id_naracka) references project.Naracka (id_naracka)
|
|---|
| 64 | );
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 | create table project.Magacin(
|
|---|
| 69 | id_magacin serial primary key,
|
|---|
| 70 | lokacija varchar(50) not null
|
|---|
| 71 | );
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 | create table project.Kategorija(
|
|---|
| 76 | id_kategorija serial primary key,
|
|---|
| 77 | ime varchar(50) not null
|
|---|
| 78 | );
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 | create table project.Produkt(
|
|---|
| 82 | id_produkt serial primary key,
|
|---|
| 83 | ime varchar(50) not null,
|
|---|
| 84 | opis varchar(200),
|
|---|
| 85 | id_korisnik serial,
|
|---|
| 86 | constraint fk_produkt_admin foreign key (id_korisnik) references project.Admin_korisnik(id_korisnik)
|
|---|
| 87 | );
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 | create table project.Cena(
|
|---|
| 91 | id_produkt serial,
|
|---|
| 92 | cena_od date not null,
|
|---|
| 93 | cena_do date,
|
|---|
| 94 | iznos integer not null,
|
|---|
| 95 | constraint pk_cena primary key (id_produkt, cena_od),
|
|---|
| 96 | constraint fk_cena_produkt foreign key (id_produkt) references project.Produkt (id_produkt)
|
|---|
| 97 | );
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 | create table project.naracka_sodrzi_produkt(
|
|---|
| 101 | id_produkt serial,
|
|---|
| 102 | id_naracka serial,
|
|---|
| 103 | kolicina integer not null,
|
|---|
| 104 | cena integer not null,
|
|---|
| 105 | constraint pk_naracka_sodrzi_produkt primary key(id_produkt, id_naracka),
|
|---|
| 106 | constraint fk_n_s_p_p foreign key (id_produkt) references project.Produkt(id_produkt),
|
|---|
| 107 | constraint fk_n_s_p_n foreign key (id_naracka) references project.Naracka(id_naracka)
|
|---|
| 108 | );
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 | create table project.produkt_e_vo_magacin(
|
|---|
| 112 | id_produkt serial,
|
|---|
| 113 | id_magacin serial,
|
|---|
| 114 | kolicina integer not null,
|
|---|
| 115 | constraint pk_produkt_e_vo_magacin primary key(id_produkt, id_magacin),
|
|---|
| 116 | constraint fk_p_e_vo_m_p foreign key (id_produkt) references project.Produkt (id_produkt),
|
|---|
| 117 | constraint fk_p_e_vo_m_m foreign key (id_magacin) references project.Magacin (id_magacin)
|
|---|
| 118 | );
|
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 | create table project.produkt_e_od_kategorija(
|
|---|
| 123 | id_produkt serial,
|
|---|
| 124 | id_kategorija serial,
|
|---|
| 125 | constraint pk_produkt_e_od_kategorija primary key (id_produkt, id_kategorija),
|
|---|
| 126 | constraint fk_p_e_od_k_p foreign key (id_produkt) references project.Produkt(id_produkt),
|
|---|
| 127 | constraint fk_p_e_od_k_k foreign key (id_kategorija) references project.Kategorija(id_kategorija)
|
|---|
| 128 | );
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 | drop table project.Kupuvac;
|
|---|
| 132 | drop table project.Korisnik;
|
|---|
| 133 | drop table project.Admin_korisnik;
|
|---|
| 134 | drop table project.Dostavuvac;
|
|---|
| 135 | drop table project.Magacioner;
|
|---|
| 136 | drop table project.Telefonskibroj;
|
|---|
| 137 | drop table project.Dostava;
|
|---|
| 138 | drop table project.Magacin;
|
|---|
| 139 | drop table project.Naracka;
|
|---|
| 140 | drop table project.Kategorija;
|
|---|
| 141 | drop table project.Produkt;
|
|---|
| 142 | drop table project.Cena;
|
|---|
| 143 | drop table project.naracka_sodrzi_produkt;
|
|---|
| 144 | drop table project.produkt_e_vo_magacin;
|
|---|
| 145 | drop table project.produkt_e_od_kategorija; |
|---|