Gaurav-2273 commited on
Commit
ad8f113
·
verified ·
1 Parent(s): 6b69056

Create generate_db.py

Browse files
Files changed (1) hide show
  1. generate_db.py +28 -0
generate_db.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sqlite3
2
+
3
+ def init_db():
4
+ conn = sqlite3.connect('sales.db')
5
+ c = conn.cursor()
6
+
7
+ # Create Tables
8
+ c.execute('''CREATE TABLE IF NOT EXISTS customers
9
+ (id INTEGER PRIMARY KEY, name TEXT, region TEXT)''')
10
+ c.execute('''CREATE TABLE IF NOT EXISTS products
11
+ (id INTEGER PRIMARY KEY, name TEXT, category TEXT, price REAL)''')
12
+ c.execute('''CREATE TABLE IF NOT EXISTS orders
13
+ (id INTEGER PRIMARY KEY, customer_id INTEGER, product_id INTEGER,
14
+ quantity INTEGER, order_date DATE)''')
15
+
16
+ # Insert Dummy Data
17
+ c.execute("INSERT OR IGNORE INTO customers VALUES (1, 'Acme Corp', 'North')")
18
+ c.execute("INSERT OR IGNORE INTO customers VALUES (2, 'Globex', 'West')")
19
+ c.execute("INSERT OR IGNORE INTO products VALUES (1, 'AI Widget', 'Software', 1000.0)")
20
+ c.execute("INSERT OR IGNORE INTO products VALUES (2, 'Cloud Server', 'Hardware', 5000.0)")
21
+ c.execute("INSERT OR IGNORE INTO orders VALUES (101, 1, 1, 5, '2023-10-01')")
22
+ c.execute("INSERT OR IGNORE INTO orders VALUES (102, 2, 2, 1, '2023-10-05')")
23
+
24
+ conn.commit()
25
+ conn.close()
26
+
27
+ if __name__ == "__main__":
28
+ init_db()