-
Notifications
You must be signed in to change notification settings - Fork 0
/
Schemas.sql
56 lines (43 loc) · 983 Bytes
/
Schemas.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
-- Monday Coffee SCHEMAS
DROP TABLE IF EXISTS sales;
DROP TABLE IF EXISTS customers;
DROP TABLE IF EXISTS products;
DROP TABLE IF EXISTS city;
-- Import Rules
-- 1st import to city
-- 2nd import to products
-- 3rd import to customers
-- 4th import to sales
CREATE TABLE city
(
city_id INT PRIMARY KEY,
city_name VARCHAR(15),
population BIGINT,
estimated_rent FLOAT,
city_rank INT
);
CREATE TABLE customers
(
customer_id INT PRIMARY KEY,
customer_name VARCHAR(25),
city_id INT,
CONSTRAINT fk_city FOREIGN KEY (city_id) REFERENCES city(city_id)
);
CREATE TABLE products
(
product_id INT PRIMARY KEY,
product_name VARCHAR(35),
Price float
);
CREATE TABLE sales
(
sale_id INT PRIMARY KEY,
sale_date date,
product_id INT,
customer_id INT,
total FLOAT,
rating INT,
CONSTRAINT fk_products FOREIGN KEY (product_id) REFERENCES products(product_id),
CONSTRAINT fk_customers FOREIGN KEY (customer_id) REFERENCES customers(customer_id)
);
-- END of SCHEMAS