-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_data_tables.py
38 lines (34 loc) · 1.11 KB
/
create_data_tables.py
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
import sqlite3
def main():
conn = sqlite3.connect('final_project.db')
cur = conn.cursor()
cur.execute('DROP TABLE IF EXISTS zipcode_table')
cur.execute('DROP TABLE IF EXISTS charging_locations_table')
cur.execute('DROP TABLE IF EXISTS restaurant_locations_table')
cur.execute("""CREATE TABLE IF NOT EXISTS zipcode_table (
zip_id INTEGER PRIMARY KEY,
zipcode INTEGER NOT NULL UNIQUE,
zipcode_url TEXT,
lat FLOAT,
long FLOAT,
current_pop INTEGER,
median_income INTEGER
)""")
cur.execute("""CREATE TABLE IF NOT EXISTS charging_locations_table (
charger_id INTEGER PRIMARY KEY,
zip_id INTEGER,
name TEXT,
address TEXT,
city TEXT,
FOREIGN KEY (zip_id) REFERENCES zipcode_table (zip_id)
)""")
cur.execute("""CREATE TABLE IF NOT EXISTS restaurant_locations_table (
restaurant_id TEXT PRIMARY KEY,
zip_id INTEGER,
name TEXT,
address TEXT,
city TEXT,
FOREIGN KEY (zip_id) REFERENCES zipcode_table (zip_id)
)""")
conn.commit()
conn.close()