1 | --drop schema if exists project cascade;
|
---|
2 | create schema project;
|
---|
3 |
|
---|
4 | --drop table if exists PERSON;
|
---|
5 | --drop table if exists LIBRARY_DB;
|
---|
6 | --drop table if exists EMPLOYEE;
|
---|
7 | --drop table if exists SCHOOL_TYPE;
|
---|
8 | --drop table if exists MEMBERSHIP_TYPE;
|
---|
9 | --drop table if exists MEMBER_LIBRARY;
|
---|
10 | --drop table if exists PRICE;
|
---|
11 | --drop table if exists ROOM;
|
---|
12 | --drop table if exists BOOK;
|
---|
13 | --drop table if exists GENRE;
|
---|
14 | --drop table if exists REVIEW;
|
---|
15 | --drop table if exists WRITER;
|
---|
16 | --drop table if exists ONLINE_DOWNLOAD;
|
---|
17 | --drop table if exists RESERVATION_BOOK;
|
---|
18 | --drop table if exists RESERVATION_PLACE;
|
---|
19 | --drop table if exists MEMBERSHIP_OF_SCHOOLTYPE;
|
---|
20 | --drop table if exists WRITER_OF_BOOK;
|
---|
21 |
|
---|
22 |
|
---|
23 | create table PERSON (
|
---|
24 | id_person serial primary key,
|
---|
25 | namee varchar(9) not null,
|
---|
26 | surname varchar (12) not null,
|
---|
27 | address varchar (25) not null,
|
---|
28 | town varchar(10) not null,
|
---|
29 | phone_num varchar(15) not null,
|
---|
30 | birth date,
|
---|
31 | email varchar(45) not null,
|
---|
32 | pass varchar (16) not null
|
---|
33 | );
|
---|
34 |
|
---|
35 | create table LIBRARY_DB(
|
---|
36 | id_library serial primary key,
|
---|
37 | names varchar (30) not null,
|
---|
38 | city varchar(13) not null
|
---|
39 | );
|
---|
40 |
|
---|
41 | create table EMPLOYEE(
|
---|
42 | id_person integer primary key,
|
---|
43 | id_library integer not null,
|
---|
44 | constraint fk_idperson_employee foreign key(id_person) references PERSON (id_person),
|
---|
45 | constraint fk_library_employee foreign key(id_library) references LIBRARY_DB (id_library),
|
---|
46 | positionn varchar(14) not null
|
---|
47 | );
|
---|
48 |
|
---|
49 |
|
---|
50 | create table SCHOOL_TYPE(
|
---|
51 | id_school serial primary key,
|
---|
52 | school_type_name varchar (40) not null
|
---|
53 | );
|
---|
54 |
|
---|
55 | create table MEMBERSHIP_TYPE (
|
---|
56 | id_membership serial primary key,
|
---|
57 | mem_type_name varchar (35) not null
|
---|
58 | );
|
---|
59 |
|
---|
60 |
|
---|
61 | create table MEMBER_LIBRARY(
|
---|
62 | id_person integer primary key,
|
---|
63 | id_school integer not null,
|
---|
64 | id_membership integer not null,
|
---|
65 | id_library integer not null,
|
---|
66 | isPayedMemebership boolean not null,
|
---|
67 | isPayedBook boolean not null,
|
---|
68 | constraint fk_person_member foreign key (id_person) references PERSON (id_person),
|
---|
69 | constraint fk_school_member foreign key (id_school) references SCHOOL_TYPE (id_school),
|
---|
70 | constraint fk_membership_member foreign key (id_membership) references MEMBERSHIP_TYPE (id_membership),
|
---|
71 | constraint fk_libraryy_member foreign key (id_library) references LIBRARY_DB (id_library)
|
---|
72 | );
|
---|
73 |
|
---|
74 |
|
---|
75 | create table PRICELIST (
|
---|
76 | id_price integer primary key,
|
---|
77 | id_membership integer not null,
|
---|
78 | price integer not null,
|
---|
79 | constraint fk_membership_price foreign key (id_membership) references MEMBERSHIP_TYPE (id_membership)
|
---|
80 | );
|
---|
81 |
|
---|
82 |
|
---|
83 | create table ROOM (
|
---|
84 | id_room integer primary key,
|
---|
85 | places integer not null,
|
---|
86 | free_places integer not null,
|
---|
87 | id_library integer not null,
|
---|
88 | constraint fk_library_room foreign key (id_library) references LIBRARY_DB (id_library)
|
---|
89 | );
|
---|
90 |
|
---|
91 |
|
---|
92 | create table GENRE(
|
---|
93 | id_genre serial primary key,
|
---|
94 | namee varchar(60) not null
|
---|
95 | );
|
---|
96 |
|
---|
97 |
|
---|
98 | create table BOOK(
|
---|
99 | id_book serial primary key,
|
---|
100 | id_library integer not null,
|
---|
101 | id_genre integer not null,
|
---|
102 | namee varchar(120) not null,
|
---|
103 | book_num integer not null,
|
---|
104 | if_free boolean not null,
|
---|
105 | book_price integer not null,
|
---|
106 | book_price_late integer not null,
|
---|
107 | constraint fk_library_book foreign key (id_library) references LIBRARY_DB (id_library),
|
---|
108 | constraint fk_genre_book foreign key (id_genre) references GENRE (id_genre)
|
---|
109 | );
|
---|
110 |
|
---|
111 | create table REVIEW (
|
---|
112 | id_review integer primary key,
|
---|
113 | rent_num integer not null,
|
---|
114 | rate integer not null,
|
---|
115 | id_book integer not null,
|
---|
116 | constraint fk_book_review foreign key (id_book) references BOOK (id_book)
|
---|
117 | );
|
---|
118 |
|
---|
119 |
|
---|
120 | create table WRITER (
|
---|
121 | id_writer serial primary key,
|
---|
122 | namee varchar(70) not null,
|
---|
123 | book_num integer not null
|
---|
124 | );
|
---|
125 |
|
---|
126 |
|
---|
127 | create table ONLINE_DOWNLOAD (
|
---|
128 | id_onlineDown integer primary key,
|
---|
129 | id_book integer not null,
|
---|
130 | id_member integer not null,
|
---|
131 | downloaded integer not null,
|
---|
132 | constraint fk_book_download foreign key (id_book) references BOOK (id_book),
|
---|
133 | constraint fk_personmember_down foreign key (id_member) references MEMBER_LIBRARY (id_person)
|
---|
134 | );
|
---|
135 |
|
---|
136 |
|
---|
137 | create table RESERVATION_BOOK(
|
---|
138 | id_resBook serial primary key,
|
---|
139 | id_book integer not null,
|
---|
140 | id_member integer not null,
|
---|
141 | take_date date not null,
|
---|
142 | return_date date not null,
|
---|
143 | isReservedBook boolean not null,
|
---|
144 | constraint fk_book_reservation foreign key (id_book) references BOOK (id_book),
|
---|
145 | constraint fk_person_member_reservation foreign key (id_member) references MEMBER_LIBRARY (id_person)
|
---|
146 | );
|
---|
147 |
|
---|
148 |
|
---|
149 | create table RESERVATION_PLACE(
|
---|
150 | id_resRoom serial primary key,
|
---|
151 | id_member integer not null,
|
---|
152 | id_room integer not null,
|
---|
153 | coming_date date not null,
|
---|
154 | comingTime time not null,
|
---|
155 | leavingTime time not null,
|
---|
156 | constraint fk_person_member_place foreign key (id_member) references MEMBER_LIBRARY (id_person),
|
---|
157 | constraint fk_room_place foreign key (id_room) references ROOM (id_room)
|
---|
158 | );
|
---|
159 |
|
---|
160 |
|
---|
161 | create table MEMBERSHIP_OF_SCHOOLTYPE(
|
---|
162 | id_membership integer primary key,
|
---|
163 | id_school integer not null,
|
---|
164 | constraint fk_membership_of foreign key (id_membership) references MEMBERSHIP_TYPE (id_membership),
|
---|
165 | constraint fk_school_of foreign key (id_school) references SCHOOL_TYPE (id_school)
|
---|
166 | );
|
---|
167 |
|
---|
168 |
|
---|
169 | create table WRITER_OF_BOOK(
|
---|
170 | id_book integer primary key,
|
---|
171 | id_writer integer not null,
|
---|
172 | constraint fk_book_who_write foreign key (id_book) references BOOK (id_book),
|
---|
173 | constraint fk_write_who foreign key (id_writer) references WRITER (id_writer)
|
---|
174 | );
|
---|
175 |
|
---|
176 |
|
---|
177 | --DEL ZA BRISHENJE NA TABELI--
|
---|
178 |
|
---|
179 | --delete from PERSON;
|
---|
180 | --delete from LIBRARY_DB;
|
---|
181 | --delete from EMPLOYEE;
|
---|
182 | --delete from SCHOOL_TYPE;
|
---|
183 | --delete from MEMBERSHIP_TYPE;
|
---|
184 | --delete from MEMBER_LIBRARY;
|
---|
185 | --delete from PRICE;
|
---|
186 | --delete from ROOM;
|
---|
187 | --delete from BOOK;
|
---|
188 | --delete from GENRE;
|
---|
189 | --delete from REVIEW;
|
---|
190 | --delete from WRITER;
|
---|
191 | --delete from ONLINE_DOWNLOAD;
|
---|
192 | --delete from RESERVATION_BOOK;
|
---|
193 | --delete from RESERVATION_PLACE;
|
---|
194 | --delete from MEMBERSHIP_OF_SCHOOLTYPE;
|
---|
195 | --delete from WRITER_OF_BOOK;
|
---|
196 |
|
---|