1-Insert one record in table
2-Insert many records in table
3-Terminate
Enter Choice:1
Enter Employee No.:1
Enter Employee Name:Adhitya
Enter Employee Department:IT
Enter Date of Joining:2021/08/20
Enter Employee Salary:200000
(1, 'Adhitya', 'IT', [Link](2021, 8, 20), 200000)
1-Insert one record in table
2-Insert many records in table
3-Terminate
Enter Choice:2
Enter no. of records to Enter:2
Enter Employee No.:2
Enter Employee Name:Adhi
Enter Employee Department:HR
Enter Date of Joining:2022/02/14
Enter Employee Salary:140000
Enter Employee No.:3
Enter Employee Name:Arun
Enter Employee Department:IT
Enter Date of Joining:2020/09/08
Enter Employee Salary:240000
(1, 'Adhitya', 'IT', [Link](2021, 8, 20), 200000)
(2, 'Adhi', 'HR', [Link](2022, 2, 14), 140000)
(3, 'Arun', 'IT', [Link](2020, 9, 8), 240000)
1-Insert one record in table
2-Insert many records in table
3-Terminate
Enter Choice:3
Terminated
Code-18
import pymysql
def one_rec():
# Create a new connection and cursor
con = [Link](host="localhost", user="root", password="a!b@c#d$e%f67890")
mycursor = [Link]()
# Database and table creation
[Link]("create database if not exists students;")
[Link]("use students")
[Link]("CREATE TABLE IF NOT EXISTS EMP(Eno int, Ename varchar(30), Dept char(25), DOJ date,
Salary int)")
# User inputs
no = input("Enter Employee No.:")
name = input("Enter Employee Name:")
de = input("Enter Employee Department:")
doj = input("Enter Date of Joining:")
sal = input("Enter Employee Salary:")
# Insert record
query = "insert into emp values (%s, %s, %s, %s, %s)"
[Link](query, (no, name, de, doj, sal))
# Fetch and display records
[Link]("select * from emp;")
c = [Link]()
for i in c:
print(i)
# Commit the changes and close connection
[Link]()
[Link]()
def many_rec():
# Create a new connection and cursor
con = [Link](host="localhost", user="root", password="a!b@c#d$e%f67890")
mycursor = [Link]()
# Database and table creation
[Link]("create database if not exists students;")
[Link]("use students")
[Link]("CREATE TABLE IF NOT EXISTS EMP(Eno int, Ename varchar(30), Dept char(25), DOJ date,
Salary int)")
# Insert multiple records
n = int(input("Enter no. of records to Enter:"))
for i in range(n):
no = input("Enter Employee No.:")
name = input("Enter Employee Name:")
de = input("Enter Employee Department:")
doj = input("Enter Date of Joining:")
sal = input("Enter Employee Salary:")
query = "insert into emp values (%s, %s, %s, %s, %s)"
[Link](query, (no, name, de, doj, sal))
# Fetch and display records
[Link]("select * from emp;")
c = [Link]()
for i in c:
print(i)
# Commit the changes and close connection
[Link]()
[Link]()
# Main loop
while True:
print("1-Insert one record in table")
print("2-Insert many records in table")
print("3-Terminate")
o = int(input("Enter Choice:"))
if o == 1:
one_rec()
elif o == 2:
many_rec()
else:
print("Terminated")
break
1-Insert record in table
2-Search record using Employee Number
3-Search record using Department and Salary greater than 50000
4-Terminate
Enter Choice:1
Enter Employee No.:1
Enter Employee Name:Adhitya
Enter Employee Department:IT
Enter Date of Joining:2018/09/13
Enter Employee Salary:150000
(1, 'Adhitya', 'IT', [Link](2018, 9, 13), 150000)
1-Insert record in table
2-Search record using Employee Number
3-Search record using Department and Salary greater than 50000
4-Terminate
Enter Choice:2
Enter Employee ID:1
(1, 'Adhitya', 'IT', [Link](2018, 9, 13), 150000)
1-Insert record in table
2-Search record using Employee Number
3-Search record using Department and Salary greater than 50000
4-Terminate
Enter Choice:3
Enter Department:IT
(1, 'Adhitya', 'IT', [Link](2018, 9, 13), 150000)
1-Insert record in table
2-Search record using Employee Number
3-Search record using Department and Salary greater than 50000
4-Terminate
Enter Choice:4
Terminated
Codeeee-19
import pymysql
# Create connection and cursor
con = [Link](host="localhost", user="root", password="a!b@c#d$e%f67890")
mycursor = [Link]()
def ins_rec():
[Link]("create database if not exists students;")
[Link]("use students")
[Link]("CREATE TABLE IF NOT EXISTS EMP(Eno int, Ename varchar(30), Dept char(25), DOJ date,
Salary int)")
# Take user inputs
no = input("Enter Employee No.:")
name = input("Enter Employee Name:")
de = input("Enter Employee Department:")
doj = input("Enter Date of Joining:")
sal = input("Enter Employee Salary:")
# Insert record
query = "insert into emp values (%s, %s, %s, %s, %s)"
[Link](query, (no, name, de, doj, sal))
# Fetch and display all records
[Link]("select * from emp;")
c = [Link]()
for i in c:
print(i)
[Link]()
def search_rec():
x = int(input("Enter Employee ID:"))
[Link]("use students")
# Fetch the record based on Employee No.
[Link]("select * from emp where eno=%s", (x,))
cd = [Link]()
print(cd)
[Link]()
def more_cons():
[Link]("use students")
# Input department and check for salary > 50,000
d = input("Enter Department:")
[Link]("select * from emp where salary > 50000 and dept=%s", (d,))
cd = [Link]()
for i in cd:
print(i)
[Link]()
# Main loop
while True:
print("1-Insert record in table")
print("2-Search record using Employee Number")
print("3-Search record using Department and Salary greater than 50000")
print("4-Terminate")
o = int(input("Enter Choice:"))
if o == 1:
ins_rec()
elif o == 2:
search_rec()
elif o == 3:
more_cons()
else:
print("Terminated")
break
# Close connection after exiting the loop
[Link]()