RelationalDesign: kreiranje.sql

File kreiranje.sql, 2.4 KB (added by 193026, 3 years ago)
Line 
1drop schema if exists weservice cascade;
2create schema weservice;
3
4-- use weservice;
5
6drop table if exists business_service;
7drop table if exists review;
8drop table if exists business;
9drop table if exists service;
10drop table if exists reviewer;
11drop table if exists category;
12
13
14create table category(
15 category_id serial primary key,
16 category_name varchar(150) not null
17
18);
19
20create table reviewer(
21 reviewer_id serial primary key,
22 reviewer_name varchar(150),
23 reviewer_verified boolean not null,
24 reviewer_email varchar(150) not null,
25 reviewer_password varchar(150) not null
26);
27
28create table business(
29 business_id serial primary key,
30 business_name varchar(150) not null,
31 business_phone varchar(150),
32 business_descr varchar(500),
33 business_hours varchar(1000),
34
35 category_id integer not null,
36
37 constraint fk_business_category_id foreign key (category_id) references category(category_id)
38);
39
40create table address(
41 address_id serial,
42 address_street varchar(150) not null,
43 address_postal_code varchar(150) not null,
44 address_city varchar(150) not null,
45 business_id integer not null,
46
47 constraint pk_address_business primary key(business_id, address_id),
48
49 constraint fk_business_id foreign key (business_id) references business(business_id)
50);
51
52create table service(
53 service_id serial primary key,
54 service_name varchar(500) not null,
55 category_id integer not null,
56
57 constraint fk_service_category foreign key (category_id) references category(category_id)
58);
59
60 create table review(
61 review_id serial primary key,
62 review_title varchar(150),
63 review_text varchar(1000),
64 review_stars integer,
65 business_id integer not null,
66 address_id integer not null,
67 reviewer_id integer not null,
68
69
70 constraint fk_business_id foreign key (business_id) references business(business_id),
71 constraint fk_address_id foreign key (business_id,address_id) references address(business_id, address_id),
72 constraint fk_reviewer_id foreign key (reviewer_id) references reviewer(reviewer_id)
73 );
74
75
76create table business_service(
77 business_id integer not null,
78 service_id integer not null,
79
80 constraint pk_business_service primary key (business_id, service_id),
81
82 constraint fk_bs_business_id foreign key (business_id) references business(business_id),
83 constraint fk_bs_service_id foreign key (service_id) references service(service_id)
84);
85
86