-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathschema.sql
More file actions
33 lines (28 loc) · 985 Bytes
/
schema.sql
File metadata and controls
33 lines (28 loc) · 985 Bytes
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
-- =============================================================
-- Section 15 — Views & Materialised Views
-- =============================================================
DROP SCHEMA IF EXISTS adv_views CASCADE;
CREATE SCHEMA adv_views;
SET search_path TO adv_views;
CREATE TABLE customer (
id SERIAL PRIMARY KEY,
full_name VARCHAR(200) NOT NULL,
country CHAR(2) NOT NULL
);
CREATE TABLE product (
id SERIAL PRIMARY KEY,
name VARCHAR(200) NOT NULL,
category VARCHAR(50) NOT NULL,
price_cents INTEGER NOT NULL
);
CREATE TABLE "order" (
id SERIAL PRIMARY KEY,
customer_id INTEGER NOT NULL REFERENCES customer(id),
placed_at DATE NOT NULL
);
CREATE TABLE order_item (
id SERIAL PRIMARY KEY,
order_id INTEGER NOT NULL REFERENCES "order"(id) ON DELETE CASCADE,
product_id INTEGER NOT NULL REFERENCES product(id),
quantity INTEGER NOT NULL CHECK (quantity > 0)
);