Python SQLite – Deleting Data in Table
In this article, we will discuss how we can delete data in the table in the SQLite database from the Python program using the sqlite3 module. In SQLite database we use the following syntax to delete data from a table:
DELETE FROM table_name [WHERE Clause]
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course
To create the database, we will execute the following code:
Now we will create a python program to delete the row in a table:
- Import the required module.
- Establish the connection or create a connection object with the database using to connect() function of the sqlite3 module.
- Create a Cursor object by calling the cursor() method of the Connection object.
- Finally, trigger to execute() method on the cursor object, bypassing a DELETE statement as a parameter to it.
Example 1: (Delete some data)
Example 2: (Delete all data)