Select
import mysql.connector
mycon=mysql.connector.connect(host="localhost", user="root", passwd="admin",
database="EMPLOYEE")
mycursor=mycon.cursor()
print("\nBEFORE DELETION CONTENT OF EMP TABLE FOLLOWS: ")
mycursor.execute("SELECT * FROM EMP")
for k in mycursor:
print(k)
eno=int(input("Enter the empno which record you want to delete: "))
qr="DELETE FROM EMP WHERE empno={}".format(eno)
mycursor.execute(qr)
mycon.commit() # To save above DML tansactions to the databases otherwise will
not save permanently
print("\nAFTER DELETION CONTENT OF EMP TABLE FOLLOWS: ")
mycursor.execute("SELECT * FROM EMP")
rec=mycursor.fetchall()
for k in rec:
print(k)
mycon.close()
UPDATE
import mysql.connector
mycon=mysql.connector.connect(host="localhost", user="root",passwd="admin",
database="EMPLOYEE")
mycursor=mycon.cursor()
dno=int(input("Enter the DEPT. NO which record you want to update: "))
qr="SELECT * FROM DEPT WHERE deptno={}".format(dno)
mycursor.execute(qr)
rec=mycursor.fetchall()
print("\n Old Record is follows: ")
for k in rec:
print(k)
print("\nENTER DETAILS TO UPDATE RECORD:\n")
print("Entered DEPTNO No:",dno)
dname=input("Enter Department Name:")
loc=input("Enter Location of the Department:")
qr="UPDATE dept SET dname='{}', loc='{}' WHERE deptno={}".format(dname, loc,
dno)
print(qr)
mycursor.execute(qr)
mycon.commit()
print("\nNEW RECORD AFTER UPDATE OF TABLE: ")
mycursor.execute("SELECT * FROM DEPT")
rec=mycursor.fetchall()
for k in rec:
print(k)
mycon.close()
insert