forked from theyogicoderRI/PythonMadeEasy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew_table.py
More file actions
32 lines (25 loc) · 1.18 KB
/
new_table.py
File metadata and controls
32 lines (25 loc) · 1.18 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
import sqlite3
database = 'first_db.db'
def new_table():
# create a database connection
conn = sqlite3.connect(database)
c = conn.cursor()
# create table 1
c.execute(""" CREATE TABLE IF NOT EXISTS guitars (
guit_id integer PRIMARY KEY,
guit_brand text NOT NULL,
guit_model text,
guit_price int,
group_id int
); """)
# create table 2
c.execute(""" CREATE TABLE IF NOT EXISTS e_guitars (
e_guit_id integer PRIMARY KEY,
e_guit_brand text NOT NULL,
e_guit_model text,
e_guit_price int,
group_id integer NOT NULL,
FOREIGN KEY (group_id) REFERENCES guitars(group_id)
); """)
if __name__ == '__main__':
new_table()