Python – Delete All Rows from Sqlite Table
To delete all rows from Sqlite3 table, you can execute SQL DELETE query.
In this tutorial, we shall learn how to delete all rows or records from a Table of Sqlite Database using sqlite3 library.
Steps to Delete All Rows of Sqlite Table
The detailed steps to delete rows from sqlite3 table are:
- Make a connection to sqlite3 database.
- Get cursor from the connection.
DELETE FROM tablequery.
Example 1: Delete rows from sqlite3 Table
In this example, we will learn how to remove or delete all the records from a sqlite3 database table using DELETE FROM TABLE query.
import sqlite3 conn = sqlite3.connect('mysqlite.db') c = conn.cursor() # delete all rows from table c.execute('DELETE FROM students;',); print('We have deleted', c.rowcount, 'records from the table.') #commit the changes to db conn.commit() #close the connection conn.close()
We have deleted 18 records from the table.
Thats right. We have deleted 18 rows, which are all of them in that table.
In this tutorial of Python Examples, we learned to delete rows from sqlite3 table with the help of well detailed examples.