-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
46 lines (41 loc) · 1.16 KB
/
schema.sql
File metadata and controls
46 lines (41 loc) · 1.16 KB
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
CREATE TABLE population (
city_id SERIAL,
city varchar(155) NOT NULL ,
state varchar(155) NOT NULL ,
census int NOT NULL ,
estimates_base int NOT NULL ,
year_2010 INT NOT NULL ,
year_2011 INT NOT NULL ,
year_2012 INT NOT NULL ,
year_2013 INT NOT NULL ,
year_2014 INT NOT NULL ,
year_2015 INT NOT NULL ,
year_2016 INT NOT NULL ,
year_2017 INT NOT NULL ,
year_2018 INT NOT NULL ,
year_2019 INT NOT NULL
);
DROP TABLE avocado_data;
SELECT * FROM avocado_data;
CREATE TABLE citystate (
id serial primary key NOT NULL ,
city varchar(155) NOT NULL ,
state varchar(155) NOT NULL
);
CREATE TABLE avocado_data (
id serial primary key NOT NULL,
date date NOT NULL ,
average_price float NOT NULL,
total_volume float NOT NULL,
plu_4046_volume float NOT NULL,
plu_4225_volume float NOT NULL,
plu_4770_volume float NOT NULL,
type VARCHAR(155) NOT NULL,
year INT NOT NULL,
city VARCHAR(155) NOT NULL,
city_id INT NOT NULL
);
ALTER TABLE population
ADD FOREIGN KEY(city_id) REFERENCES citystate (id)
ALTER TABLE avocado_data
ADD FOREIGN KEY(city_id) REFERENCES citystate (id)