-
Notifications
You must be signed in to change notification settings - Fork 1
/
schema.sql
69 lines (58 loc) · 1.98 KB
/
schema.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
-- Exported from QuickDBD: https://www.quickdatabasediagrams.com/
-- Link to schema: https://app.quickdatabasediagrams.com/#/d/e2noqD
-- NOTE! If you have used non-SQL datatypes in your design, you will have to change these here.
CREATE TABLE "census" (
"zcta" CHAR(5) NOT NULL,
"population" FLOAT,
"median_age" FLOAT,
"median_household_income" FLOAT,
"per_capita_income" FLOAT,
"poverty_count" FLOAT,
"unemployment_count" FLOAT,
CONSTRAINT "pk_census" PRIMARY KEY (
"zcta"
)
);
CREATE TABLE "zip_zcta" (
"zip_code" CHAR(5) NOT NULL,
"zcta" CHAR(5) NOT NULL,
CONSTRAINT "pk_zip_zcta" PRIMARY KEY (
"zip_code","zcta"
)
);
CREATE TABLE "zip" (
"zip_code" CHAR(5) NOT NULL,
"city" VARCHAR(100) NOT NULL,
"state" VARCHAR(30) NOT NULL,
CONSTRAINT "pk_zip" PRIMARY KEY (
"zip_code"
)
);
CREATE TABLE "restaurant_address" (
"restaurant_address_id" SERIAL NOT NULL,
"restaurant_id" INT NOT NULL,
"street_no" VARCHAR(30) NOT NULL,
"street_name" VARCHAR NOT NULL,
"zip_code" CHAR(5) NOT NULL,
CONSTRAINT "pk_restaurant_address" PRIMARY KEY (
"restaurant_address_id"
)
);
CREATE TABLE "restaurant" (
"restaurant_id" INT NOT NULL,
"restaurant_name" VARCHAR NOT NULL,
CONSTRAINT "pk_restaurant" PRIMARY KEY (
"restaurant_id"
),
CONSTRAINT "uc_restaurant_restaurant_name" UNIQUE (
"restaurant_name"
)
);
ALTER TABLE "zip_zcta" ADD CONSTRAINT "fk_zip_zcta_zip_code" FOREIGN KEY("zip_code")
REFERENCES "zip" ("zip_code");
ALTER TABLE "zip_zcta" ADD CONSTRAINT "fk_zip_zcta_zcta" FOREIGN KEY("zcta")
REFERENCES "census" ("zcta");
ALTER TABLE "restaurant_address" ADD CONSTRAINT "fk_restaurant_address_restaurant_id" FOREIGN KEY("restaurant_id")
REFERENCES "restaurant" ("restaurant_id");
ALTER TABLE "restaurant_address" ADD CONSTRAINT "fk_restaurant_address_zip_code" FOREIGN KEY("zip_code")
REFERENCES "zip" ("zip_code");