CBSE Class 12 Computer Science Question 35 of 47

Interface Python with SQL — Question 13

Back to all questions
13
Question

Question 13

Write a program to delete the employee record whose name is read from keyboard at execution time.

Answer
import mysql.connector
mydb = mysql.connector.connect(host = "localhost",
                                user = "root",
                                passwd = "tiger",
                                database = "School")
mycursor = mydb.cursor()
employee_name = input("Enter the name of the employee to delete: ")
mycursor.execute("DELETE FROM employee WHERE ENAME = %s", (employee_name,))
print(mycursor.rowcount, "Record Deleted")
Output
Enter the name of the employee to delete: RAJESH
1 Record Deleted