0% found this document useful (0 votes)
3 views2 pages

Program19 (Py SQL Update Record)

The document provides a Python program that integrates SQL to update employee records in a MySQL database. It connects to the database, allows the user to search for an employee by their number, and prompts for confirmation before updating the salary. The program also includes functionality to display all employee records after updates are made.

Uploaded by

lakshin1226
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Program19 (Py SQL Update Record)

The document provides a Python program that integrates SQL to update employee records in a MySQL database. It connects to the database, allows the user to search for an employee by their number, and prompts for confirmation before updating the salary. The program also includes functionality to display all employee records after updates are made.

Uploaded by

lakshin1226
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

'''Write a python program to integrate SQL with python

by importing the MYSQL module to update the employee record of entered


empno.'''
[Link]
con=[Link](host='localhost',user='root',
password='admin',database='geetha')
cur=[Link]()
print("EMPLOYEE SEARCHING FORM")
ans='y'
[Link]()=='y':
eno=input("Enter Employee Number to be updated:")
query="select * from employee where eno={}".format(eno)
[Link](query)
result=[Link]()
[Link]==0:
print("Sorry!Empno not found")
else :
print("%12s"%"EMPNO","%20s"%"NAME","%15s"%"Esal")
for row in result:
print("%10s"%row[0],"%23s"%row[1],"%15s"%row[2])
choice=input("\nAre you sure you want to update?(Y):")
[Link]()=='y':
print("==You can update details==")
d=input("Enter new salary:")
if d=="":
d=row[2]
query="update employee set Esal={} where eno={}".format(d,eno)
[Link](query)
[Link]()
print("Record Updated")
ans=input("Do you want to update more?(y):")
query="select * from employee"
[Link](query)
for i in cur:
print(i)
OUTPUT :

You might also like