File size: 1,287 Bytes
31812e1 |
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 47 48 49 |
import sqlite3
DB_PATH = "database.sqlite"
def get_connection():
return sqlite3.connect(DB_PATH)
def create_tables():
conn = get_connection()
cursor = conn.cursor()
cursor.execute('''CREATE TABLE IF NOT EXISTS Employees(
ID INTEGER PRIMARY KEY AUTOINCREMENT,
Name TEXT NOT NULL,
Department TEXT NOT NULL,
Salary INTEGER NOT NULL,
Hire_Date TEXT NOT NULL
)
''')
cursor.execute('''CREATE TABLE IF NOT EXISTS Departments(
ID INTEGER PRIMARY KEY AUTOINCREMENT,
Name TEXT NOT NULL,
Manager TEXT NOT NULL
)
''')
employees = [
(1, 'Alice', 'Sales', 50000, '2021-01-15'),
(2, 'Bob', 'Engineering', 70000, '2020-06-10'),
(3, 'Charlie', 'Marketing', 60000, '2022-03-20')
]
departments = [
(1, 'Sales', 'Alice'),
(2, 'Engineering', 'Bob'),
(3, 'Marketing', 'Charlie')
]
cursor.executemany('INSERT INTO Employees VALUES (?,?,?,?,?)', employees)
cursor.executemany('INSERT INTO Departments VALUES (?,?,?)', departments)
conn.commit()
conn.close()
if __name__ == "__main__":
create_tables() |