-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathcreate_table.sql
113 lines (83 loc) · 2.48 KB
/
create_table.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* Creating geolocation table */
CREATE TABLE geo_location(
zipcode char(5),
latitude double precision,
longitude double precision,
city varchar(50),
geostate char(2)
);
/* Creating customers datatable */
CREATE TABLE customers(
customer_id varchar(50),
customer_unique_id varchar(50),
customer_zipcode char(5),
customer_city varchar(50),
customer_state char(2),
CONSTRAINT customer_key PRIMARY KEY (customer_id)
);
/* Creating sellers table */
CREATE TABLE sellers(
seller_id varchar(50),
seller_zipcode char(5),
seller_city varchar(50),
seller_state varchar(5),
CONSTRAINT seller_key PRIMARY KEY (seller_id)
);
/* Creating product table */
CREATE TABLE products(
product_id varchar(50),
product_category varchar(50),
product_name_length smallint,
product_desc_length smallint,
product_photos_qty smallint,
product_weight_grams integer,
product_length_cm smallint,
product_height_cm smallint,
product_width_cm smallint,
CONSTRAINT product_key PRIMARY KEY (product_id)
);
/* Creating order datatable */
CREATE TABLE orders(
order_id varchar(50),
customer_id varchar(50) REFERENCES customers (customer_id),
order_status varchar(50),
order_purchase timestamp,
order_approved timestamp,
order_delivered_carrier timestamp,
order_delivered_customer timestamp,
order_estimated_delivery timestamp,
CONSTRAINT order_key PRIMARY KEY (order_id)
);
/* Creating order_payments datatable */
CREATE TABLE order_payments(
order_id varchar(50) REFERENCES orders (order_id),
payment_sequential smallint,
payment_type varchar(20),
payment_installments smallint,
payment_value double precision
);
/* Creating order_review datatable */
CREATE TABLE order_reviews(
review_id varchar(50),
order_id varchar(50) REFERENCES orders (order_id),
review_score smallint,
review_title text,
review_comment text,
review_create timestamp,
review_answer timestamp
);
/* Creating order_item table */
CREATE TABLE order_items(
order_id varchar(50) REFERENCES orders (order_id),
order_item_id smallint,
product_id varchar(50) REFERENCES products (product_id),
seller_id varchar(50) REFERENCES sellers (seller_id),
shipping_limit_date timestamp,
price real,
freight_value real
);
/* Creating product_translation table */
CREATE TABLE product_translation(
category varchar(50),
category_translation varchar(50)
);