Program 1: Create Employee Table
Write a program to create an Employee table and insert records.
import sqlite3
print("\nProgram 1: Create Employee Table\n")
conn = sqlite3.connect(":memory:")
cursor = conn.cursor()
cursor.execute("CREATE TABLE Employee (EmpID INTEGER PRIMARY KEY, Name TEXT, Salary INTEGER)")
cursor.executemany("INSERT INTO Employee VALUES (?, ?, ?)", [
(1, "Amit", 50000),
(2, "Neha", 60000),
(3, "Rajesh", 55000)
])
cursor.execute("SELECT * FROM Employee")
for row in cursor.fetchall():
print(row)
conn.close()
Program 2: Select Employees with Salary > 55000
Write a program to select employees whose salary is greater than 55000.
import sqlite3
print("\nProgram 2: Select Employees with Salary > 55000\n")
conn = sqlite3.connect(":memory:")
cursor = conn.cursor()
cursor.execute("CREATE TABLE Employee (EmpID INTEGER PRIMARY KEY, Name TEXT, Salary INTEGER)")
cursor.executemany("INSERT INTO Employee VALUES (?, ?, ?)", [
(1, "Amit", 50000),
(2, "Neha", 60000),
(3, "Rajesh", 55000)
])
cursor.execute("SELECT * FROM Employee WHERE Salary > 55000")
for row in cursor.fetchall():
print(row)
conn.close()