RelationaDesign: krerianje(ddl).sql

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