[bc39b15] | 1 | --BRISENJE TABELI
|
---|
| 2 | drop table if exists chovek cascade;
|
---|
| 3 | drop table if exists authentication cascade;
|
---|
| 4 | drop table if exists chlen cascade;
|
---|
| 5 | drop table if exists bibliotekar cascade;
|
---|
| 6 | drop table if exists avtor cascade;
|
---|
| 7 | drop table if exists kategorija cascade;
|
---|
| 8 | drop table if exists izdavac cascade;
|
---|
| 9 | drop table if exists dobavuvac cascade;
|
---|
| 10 | drop table if exists knigi cascade;
|
---|
| 11 | drop table if exists izdava cascade;
|
---|
| 12 | drop table if exists e_od cascade;
|
---|
| 13 | drop table if exists ocena cascade;
|
---|
| 14 | drop table if exists instanca_od_kniga cascade;
|
---|
| 15 | drop table if exists pozajmica cascade;
|
---|
| 16 | drop table if exists kazna cascade;
|
---|
| 17 |
|
---|
| 18 |
|
---|
| 19 | --DODAVANJE TABELI
|
---|
| 20 | -----------------------------------------
|
---|
| 21 |
|
---|
| 22 | create table chovek(
|
---|
| 23 | id_chovek serial primary key,
|
---|
| 24 | ime varchar(50) not null,
|
---|
| 25 | prezime varchar(50) not null,
|
---|
| 26 | email varchar(50) not null,
|
---|
| 27 | tel_broj varchar(25) not null,
|
---|
| 28 | adresa varchar(150) not null,
|
---|
| 29 | embg char(13) not null,
|
---|
| 30 | username varchar(50) not null,
|
---|
| 31 | password varchar(100) not null
|
---|
| 32 | );
|
---|
| 33 |
|
---|
| 34 | -----------------------------------------
|
---|
| 35 |
|
---|
| 36 | create table authentication(
|
---|
| 37 | log_id serial primary key,
|
---|
| 38 | timestamp_log timestamp not null,
|
---|
| 39 | id_chovek integer not null,
|
---|
| 40 | constraint fk_id_chovek foreign key (id_chovek) references chovek (id_chovek)
|
---|
| 41 | );
|
---|
| 42 |
|
---|
| 43 | -----------------------------------------
|
---|
| 44 |
|
---|
| 45 | create table chlen(
|
---|
| 46 | id_chovek serial primary key,
|
---|
| 47 | broj integer not null,
|
---|
| 48 | datum_na_zachlenuvanje timestamp not null,
|
---|
| 49 | constraint fk_id_chovek foreign key (id_chovek) references chovek (id_chovek)
|
---|
| 50 | );
|
---|
| 51 |
|
---|
| 52 | -----------------------------------------
|
---|
| 53 |
|
---|
| 54 | create table bibliotekar(
|
---|
| 55 | id_chovek serial primary key,
|
---|
| 56 | id_na_bibliotekar integer not null,
|
---|
| 57 | constraint fk_id_chovek foreign key (id_chovek) references chovek (id_chovek)
|
---|
| 58 | );
|
---|
| 59 |
|
---|
| 60 | -----------------------------------------
|
---|
| 61 |
|
---|
| 62 | create table avtor(
|
---|
| 63 | id_na_avtor serial primary key,
|
---|
| 64 | ime varchar(100) not null
|
---|
| 65 | );
|
---|
| 66 |
|
---|
| 67 | -----------------------------------------
|
---|
| 68 |
|
---|
| 69 | create table kategorija(
|
---|
| 70 | id_na_kategorija serial primary key,
|
---|
| 71 | ime_kategorija varchar(30) not null
|
---|
| 72 | );
|
---|
| 73 |
|
---|
| 74 | -----------------------------------------
|
---|
| 75 |
|
---|
| 76 | create table izdavac(
|
---|
| 77 | id_na_izdavac serial primary key,
|
---|
| 78 | email varchar(50) not null,
|
---|
| 79 | lokacija varchar(200) not null,
|
---|
| 80 | ime_na_izdavac varchar(100) not null
|
---|
| 81 | );
|
---|
| 82 |
|
---|
| 83 | -----------------------------------------
|
---|
| 84 |
|
---|
| 85 | create table dobavuvac(
|
---|
| 86 | id_na_dobavuvac serial primary key,
|
---|
| 87 | ime_na_dobavuvac varchar(100) not null
|
---|
| 88 | );
|
---|
| 89 |
|
---|
| 90 | -----------------------------------------
|
---|
| 91 |
|
---|
| 92 | create table knigi(
|
---|
| 93 | id_na_kniga serial primary key,
|
---|
| 94 | opis varchar(5500) not null,
|
---|
| 95 | naslov varchar (100) not null,
|
---|
| 96 | id_izdavac integer not null,
|
---|
| 97 | constraint fk_id_izdavac foreign key (id_izdavac) references izdavac(id_na_izdavac)
|
---|
| 98 | );
|
---|
| 99 |
|
---|
| 100 | -----------------------------------------
|
---|
| 101 |
|
---|
| 102 | create table izdava(
|
---|
| 103 | id_avtor serial not null,
|
---|
| 104 | id_knigi serial not null,
|
---|
| 105 | constraint pk_izdadeno primary key (id_knigi, id_avtor),
|
---|
| 106 | constraint fk_id_avtor foreign key (id_avtor) references avtor (id_na_avtor),
|
---|
| 107 | constraint fk_id_knigi foreign key (id_knigi) references knigi (id_na_kniga)
|
---|
| 108 | );
|
---|
| 109 |
|
---|
| 110 | -----------------------------------------
|
---|
| 111 |
|
---|
| 112 | create table e_od(
|
---|
| 113 | id_na_kategorija serial not null,
|
---|
| 114 | id_knigi serial not null,
|
---|
| 115 | constraint pk_e_od primary key (id_knigi, id_na_kategorija),
|
---|
| 116 | constraint fk_id_na_kategorija foreign key (id_na_kategorija) references kategorija (id_na_kategorija),
|
---|
| 117 | constraint fk_id_knigi foreign key (id_knigi) references knigi(id_na_kniga)
|
---|
| 118 | );
|
---|
| 119 |
|
---|
| 120 | -----------------------------------------
|
---|
| 121 |
|
---|
| 122 | create table ocena(
|
---|
| 123 | id_na_ocena serial primary key,
|
---|
| 124 | ocena integer not null,
|
---|
| 125 | komentar varchar(500) not null,
|
---|
| 126 | id_chovek_dava integer not null,
|
---|
| 127 | ocena_id_kniga integer,
|
---|
| 128 | ocena_id_avtor integer,
|
---|
| 129 | constraint fk_id_chovek_dava foreign key (id_chovek_dava) references chlen (id_chovek),
|
---|
| 130 | constraint fk_ocena_id_kniga foreign key (ocena_id_kniga) references knigi (id_na_kniga),
|
---|
| 131 | constraint fk_ocena_id_avtor foreign key (ocena_id_avtor) references avtor (id_na_avtor)
|
---|
| 132 | );
|
---|
| 133 |
|
---|
| 134 | -----------------------------------------
|
---|
| 135 |
|
---|
| 136 | create table instanca_od_kniga(
|
---|
| 137 | unique_id serial,
|
---|
| 138 | dali_e_ostetena boolean not null,
|
---|
| 139 | status boolean not null,
|
---|
| 140 | id_na_dobavuvac integer not null,
|
---|
| 141 | id_na_kniga integer not null,
|
---|
| 142 | constraint pk_id_na_kniga primary key (id_na_kniga,unique_id),
|
---|
| 143 | constraint fk_id_na_kniga foreign key (id_na_kniga) references knigi (id_na_kniga),
|
---|
| 144 | constraint fk_id_na_dobavuvac foreign key (id_na_dobavuvac) references dobavuvac (id_na_dobavuvac)
|
---|
| 145 | );
|
---|
| 146 |
|
---|
| 147 | -----------------------------------------
|
---|
| 148 |
|
---|
| 149 | create table pozajmica(
|
---|
| 150 | id_na_pozajmica serial primary key,
|
---|
| 151 | datum_na_zemanje date not null,
|
---|
| 152 | datum_na_vrakjanje date not null,
|
---|
| 153 | status boolean not null,
|
---|
| 154 | id_chovek_odobruva integer not null,
|
---|
| 155 | id_chovek_prave integer not null,
|
---|
| 156 | unique_id integer not null,
|
---|
| 157 | id_na_kniga integer not null,
|
---|
| 158 | constraint fk_id_chovek_odobruva foreign key (id_chovek_odobruva) references bibliotekar (id_chovek),
|
---|
| 159 | constraint fk_id_chovek_prave foreign key (id_chovek_prave) references chlen (id_chovek),--,
|
---|
| 160 | constraint fk_unique_id foreign key (id_na_kniga,unique_id) references instanca_od_kniga(id_na_kniga,unique_id)
|
---|
| 161 | );
|
---|
| 162 |
|
---|
| 163 | -----------------------------------------
|
---|
| 164 |
|
---|
| 165 | create table kazna(
|
---|
| 166 | id_kazna serial primary key,
|
---|
| 167 | datum date not null,
|
---|
| 168 | cena_vo_denari FLOAT not null,
|
---|
| 169 | id_pozajmica_proverka integer not null,
|
---|
| 170 | id_chovek_imakazna integer not null,
|
---|
| 171 | constraint fk_id_pozajmica_proverka foreign key (id_pozajmica_proverka) references pozajmica (id_na_pozajmica),
|
---|
| 172 | constraint fk_id_chovek_imakazna foreign key (id_chovek_imakazna) references chlen (id_chovek)
|
---|
| 173 | );
|
---|
| 174 |
|
---|
| 175 | -----------------------------------------
|
---|
| 176 |
|
---|