RelationalDesign: kreiranje.sql

File kreiranje.sql, 6.3 KB (added by 196021, 3 years ago)
Line 
1drop schema if exists project cascade;
2create schema project;
3
4--use project
5
6drop table if exists users cascade;
7drop table if exists movie cascade;
8drop table if exists employee cascade;
9drop table if exists genre cascade;
10drop table if exists movieProjection cascade;
11drop table if exists firm cascade;
12drop table if exists auditorium cascade;
13drop table if exists seat cascade;
14drop table if exists client cascade;
15drop table if exists payment cascade;
16drop table if exists Payment_Type cascade;
17drop table if exists is_ cascade;
18drop table if exists controles cascade;
19
20------------------------------------------------------
21
22
23create table users(
24
25 user_id serial primary key,
26 user_username varchar(150) not null,
27 user_password varchar(150) not null,
28 user_phone_number varchar(150),
29 user_name varchar(150) not null,
30 user_surname varchar(150) not null,
31 user_email varchar(150) ,
32 user_role varchar(100)
33
34);
35
36
37------------------------------------------------------
38
39create table employee(
40
41 employee_id serial,
42 user_id integer not null,
43 constraint fk_employee_users_ foreign key (user_id) references users(user_id),
44 constraint pk_employee_users primary key (user_id)
45
46);
47
48
49
50------------------------------------------------------
51
52
53create table client(
54 client_id serial,
55 user_id integer not null,
56 constraint fk_client_users_ foreign key (user_id) references users(user_id),
57 constraint pk_client_users primary key (user_id)
58);
59
60
61------------------------------------------------------
62
63
64create table genre(
65 genre_id serial primary key,
66 genre_name varchar (150) not null
67);
68
69
70------------------------------------------------------
71
72
73create table movie(
74
75 movie_id integer primary key,
76 movie_name varchar(150) not null,
77 movie_age_category varchar(150) not null,
78 movie_production varchar(150) not null,
79 movie_film_director varchar(150) not null,
80 movie_cast varchar(250) not null,
81 movie_time_duration varchar(150) not null
82
83);
84
85------------------------------------------------------
86
87
88create table firm(
89
90firm_id serial primary key,
91firm_city varchar(100) not null,
92firm_adress varchar(100) not null,
93firm_name varchar(100) not null
94
95);
96
97
98------------------------------------------------------
99
100
101create table auditorium(
102auditorium_id serial primary key,
103auditorium_name varchar(100) not null,
104auditorium_capacity integer not null,
105
106firm_id integer not null,
107 constraint fk_auditorium_firm foreign key (firm_id) references firm(firm_id)
108);
109
110
111------------------------------------------------------
112
113
114create table movieProjection(
115 projection_id serial primary key,
116 projection_movie_start varchar(150) not null,
117 projection_movie_end varchar(150) not null,
118 projection_screening_date varchar(150) not null,
119 projection_type varchar(150) not null,
120 projection_price float8 not null,
121
122 movie_id integer not null,
123 constraint fk_movieProjection_movie foreign key (movie_id) references movie(movie_id)
124
125);
126
127
128------------------------------------------------------
129
130
131create table works_in(
132works_from varchar(150) not null,
133works_to varchar(150),
134
135user_id integer not null,
136firm_id integer not null,
137
138constraint pk_works_in_firm primary key (user_id,firm_id),
139constraint fk_works_in_firm foreign key (firm_id) references firm(firm_id),
140constraint fk_works_in_employee foreign key (user_id) references employee(user_id)
141
142);
143
144
145------------------------------------------------------
146
147
148create table Payment_Type(
149
150
151payment_type_id serial primary key,
152payment_type varchar(150) not null
153
154
155);
156
157
158------------------------------------------------------
159
160create table seat(
161seat_id serial ,
162seat_number integer not null,
163auditorium_id integer not null,
164constraint pk_seat_auditorium primary key (auditorium_id,seat_id),
165constraint fk_seat_auditorium foreign key (auditorium_id) references auditorium(auditorium_id)
166);
167
168
169------------------------------------------------------
170
171
172create table reservation(
173reservation_id serial primary key,
174reservation_date date not null,
175payment_type_id integer not null,
176constraint fk_reservation_Payment_Type foreign key (payment_type_id) references Payment_Type(payment_type_id),
177user_id integer not null,
178constraint fk_reservation_client foreign key (user_id) references client(user_id),
179auditorium_id integer not null,
180seat_id integer not null,
181constraint fk_seat_id foreign key (auditorium_id,seat_id) references seat(auditorium_id,seat_id),
182projection_id integer not null,
183constraint fk_reservation_movieProjection foreign key (projection_id) references movieProjection(projection_id)
184);
185
186
187
188------------------------------------------------------
189
190
191
192create table payment(
193payment_id serial primary key,
194payment_date date not null,
195user_id integer not null,
196constraint fk_payment_client foreign key (user_id) references client(user_id),
197payment_type_id integer not null,
198constraint fk_payment_payment_type foreign key (payment_type_id) references payment_type(payment_type_id),
199reservation_id integer not null,
200constraint fk_payment_reservation foreign key (reservation_id) references reservation(reservation_id)
201);
202
203------------------------------------------------------
204
205
206create table controles(
207user_id integer not null,
208projection_id integer not null,
209constraint pk_controles_user primary key (user_id,projection_id),
210constraint fk_controles_employee foreign key (user_id) references employee(user_id),
211constraint fk_controles_movieProjection foreign key (projection_id) references movieProjection(projection_id)
212);
213
214
215------------------------------------------------------
216
217create table is_(
218genre_id integer not null,
219movie_id integer not null,
220constraint pk_is_genre primary key (movie_id,genre_id),
221constraint fk_is_movie foreign key (movie_id) references movie(movie_id),
222constraint fk_controles_genre foreign key (genre_id) references genre(genre_id)
223);
224
225------------------------------------------------------
226
227create table gives(
228seat_limitation integer not null,
229projection_id integer not null,
230auditorium_id integer not null,
231constraint fk_gives_movieProjection foreign key (projection_id) references movieProjection(projection_id),
232constraint fk_gives_auditorium foreign key (auditorium_id) references auditorium(auditorium_id),
233constraint pk_gives_movieProjection primary key (auditorium_id,projection_id)
234);
235
236------------------------------------------------------
237
238
239