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