python-mysql-delete-from

Get Started: Python MySQL Delete From

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')

				
			

Notice: The WHERE clause specifies which record should be deleted. If you omit the WHERE clause, all records will be deleted.

If you find anything incorrect in the above-discussed topic and have further questions, please comment below.

Connect on:

Recent Post

Popular Post

Top Articles

Archives
Categories

Share on