-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomer_db.py
More file actions
31 lines (25 loc) · 823 Bytes
/
customer_db.py
File metadata and controls
31 lines (25 loc) · 823 Bytes
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
import sqlite3
conn = sqlite3.connect('customers.db')
cursor = conn.cursor()
# Drop the old table (⚠️ this deletes existing data)
cursor.execute('DROP TABLE IF EXISTS customers')
# Recreate with full schema
cursor.execute('''
CREATE TABLE customers (
id INTEGER PRIMARY KEY AUTOINCREMENT,
first_name TEXT NOT NULL,
last_name TEXT NOT NULL,
birthday TEXT,
email TEXT UNIQUE NOT NULL,
phone TEXT,
preferred_contact TEXT
)
''')
for column in ["street_address", "city", "state_province", "zip_postal"]:
try:
cursor.execute(f"ALTER TABLE customers ADD COLUMN {column} TEXT")
except sqlite3.OperationalError:
pass # Already exists
conn.commit()
conn.close()
print("Table recreated with full schema.")