In This Article, You Will Know About Python MySQL Delete From.
Python MySQL Delete From – Before moving ahead, let’s know a bit about Python MySQL Order By.
Table of Contents
Delete Record
Use “DELETE FROM” statement to delete records from existing table.
Example: Use “DELETE FROM” statement to delete the whole row of roll_no = 5204.
import mysql.connector
my_user_details = mysql.connector.connect(host="localhost",
username="your_MySQL_username",
password="Your_MySQL_password",
database="YOUR_MYSQL_DATABASE_NAME")
database_for_mysql = my_user_details.cursor()
database_for_mysql.execute("DELETE FROM Stu_information WHERE roll_no = 5204")
my_user_details.commit()
print(database_for_mysql.rowcount, 'record is deleted')
Example: Use “DELETE FROM” statement to delete the whole row of class = 10TH.
import mysql.connector
my_user_details = mysql.connector.connect(host="localhost",
username="your_MySQL_username",
password="Your_MySQL_password",
database="YOUR_MYSQL_DATABASE_NAME")
database_for_mysql = my_user_details.cursor()
database_for_mysql.execute("DELETE FROM Stu_information WHERE class = '10TH'")
my_user_details.commit()
print(database_for_mysql.rowcount, ' record is deleted')