-
Notifications
You must be signed in to change notification settings - Fork 0
/
create.sql
44 lines (38 loc) · 1.11 KB
/
create.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
BEGIN;
DROP TABLE IF EXISTS "clients";
CREATE TABLE "clients" (
"id" SERIAL PRIMARY KEY,
"name" VARCHAR NOT NULL,
"age" INTEGER NOT NULL,
"gender" VARCHAR NOT NULL check ("gender" = 'Male' or "gender" = 'Female'),
"occupation" VARCHAR NOT NULL,
"nationality" VARCHAR NOT NULL
);
DROP TABLE IF EXISTS "dishes";
CREATE TABLE "dishes" (
"id" SERIAL PRIMARY KEY,
"name" VARCHAR NOT NULL
);
DROP TABLE IF EXISTS "restaurants";
CREATE TABLE "restaurants" (
"id" SERIAL PRIMARY KEY,
"name" VARCHAR NOT NULL,
"category" VARCHAR NOT NULL,
"city" VARCHAR NOT NULL,
"address" VARCHAR NOT NULL
);
DROP TABLE IF EXISTS "restaurants_dishes";
CREATE TABLE "restaurants_dishes" (
"id" SERIAL PRIMARY KEY,
"restaurant_id" INTEGER NOT NULL REFERENCES "restaurants"("id"),
"dish_id" INTEGER NOT NULL REFERENCES "dishes"("id"),
"price" INTEGER NOT NULL
);
DROP TABLE IF EXISTS "visits";
CREATE TABLE "visits" (
"id" SERIAL PRIMARY KEY,
"date" DATE NOT NULL,
"client_id" INTEGER NOT NULL REFERENCES "clients"("id"),
"restaurant_dish_id" INTEGER NOT NULL REFERENCES "restaurants_dishes"("id")
);
COMMIT;