source: assets/create.sql

Last change on this file was 0791611, checked in by sstalevska <sara.stalevska@…>, 2 years ago

Push the entire project.

  • Property mode set to 100644
File size: 2.3 KB
Line 
1DROP TABLE IF EXISTS ADDRESS CASCADE;
2
3
4DROP TABLE IF EXISTS BUSINESS CASCADE;
5
6
7DROP TABLE IF EXISTS BUSINESS_SERVICE CASCADE;
8
9
10DROP TABLE IF EXISTS REVIEW CASCADE;
11
12
13DROP TABLE IF EXISTS SERVICE CASCADE;
14
15
16DROP TABLE IF EXISTS REVIEWER CASCADE;
17
18
19DROP TABLE IF EXISTS CATEGORY CASCADE;
20
21
22CREATE TABLE CATEGORY(CATEGORY_ID serial PRIMARY KEY,
23 CATEGORY_NAME VARCHAR(150) NOT NULL);
24
25
26CREATE TABLE REVIEWER(REVIEWER_ID serial PRIMARY KEY,
27 REVIEWER_NAME VARCHAR(150),
28 REVIEWER_VERIFIED boolean NOT NULL,
29 REVIEWER_EMAIL VARCHAR(150) NOT NULL,
30 REVIEWER_PASSWORD VARCHAR(150) NOT NULL);
31
32
33CREATE TABLE BUSINESS(BUSINESS_ID serial PRIMARY KEY,
34 BUSINESS_NAME VARCHAR(150) NOT NULL,
35 BUSINESS_PHONE VARCHAR(150),
36 BUSINESS_DESCR VARCHAR(500),
37 BUSINESS_HOURS VARCHAR(1000),
38 CATEGORY_ID integer NOT NULL,
39 CONSTRAINT FK_BUSINESS_CATEGORY_ID
40 FOREIGN KEY (CATEGORY_ID) REFERENCES CATEGORY(CATEGORY_ID));
41
42
43CREATE TABLE ADDRESS(ADDRESS_ID serial, ADDRESS_STREET VARCHAR(150) NOT NULL,
44 ADDRESS_POSTAL_CODE VARCHAR(150) NOT NULL,
45 ADDRESS_CITY VARCHAR(150) NOT NULL,
46 BUSINESS_ID integer NOT NULL,
47 CONSTRAINT PK_ADDRESS_BUSINESS PRIMARY KEY(BUSINESS_ID,
48 ADDRESS_ID),
49 CONSTRAINT FK_BUSINESS_ID
50 FOREIGN KEY (BUSINESS_ID) REFERENCES BUSINESS(BUSINESS_ID));
51
52
53CREATE TABLE SERVICE(SERVICE_ID serial PRIMARY KEY,
54 SERVICE_NAME VARCHAR(500) NOT NULL,
55 CATEGORY_ID integer NOT NULL,
56 CONSTRAINT FK_SERVICE_CATEGORY
57 FOREIGN KEY (CATEGORY_ID) REFERENCES CATEGORY(CATEGORY_ID));
58
59
60CREATE TABLE REVIEW(REVIEW_ID serial PRIMARY KEY,
61 REVIEW_TITLE VARCHAR(150),
62 REVIEW_TEXT VARCHAR(1000),
63 REVIEW_STARS integer, BUSINESS_ID integer NOT NULL,
64 ADDRESS_ID integer NOT NULL,
65 REVIEWER_ID integer NOT NULL,
66 review_timestamp timestamp default current_timestamp,
67 CONSTRAINT FK_BUSINESS_ID
68 FOREIGN KEY (BUSINESS_ID) REFERENCES BUSINESS(BUSINESS_ID),
69 CONSTRAINT FK_ADDRESS_ID
70 FOREIGN KEY (BUSINESS_ID,
71 ADDRESS_ID) REFERENCES ADDRESS(BUSINESS_ID,
72 ADDRESS_ID),
73 CONSTRAINT FK_REVIEWER_ID
74 FOREIGN KEY (REVIEWER_ID) REFERENCES REVIEWER(REVIEWER_ID));
75
76
77CREATE TABLE BUSINESS_SERVICE(BUSINESS_ID integer NOT NULL,
78 SERVICE_ID integer NOT NULL,
79 CONSTRAINT PK_BUSINESS_SERVICE PRIMARY KEY (BUSINESS_ID,
80 SERVICE_ID), CONSTRAINT FK_BS_BUSINESS_ID
81 FOREIGN KEY (BUSINESS_ID) REFERENCES BUSINESS(BUSINESS_ID),
82 CONSTRAINT FK_BS_SERVICE_ID
83 FOREIGN KEY (SERVICE_ID) REFERENCES SERVICE(SERVICE_ID));
Note: See TracBrowser for help on using the repository browser.