SQLite DELETE Statement
The DELETE Statement
The DELETE statement deletes existing records from a table.
DELETE FROM table_name WHERE condition;
Warning: Be careful when you delete records. The WHERE clause decides which records are deleted. If you leave out WHERE, all the records in the table are deleted!
Delete a Record
This example deletes the customer "Alfreds Futterkiste":
Delete Many Records
This example deletes all the customers from Mexico:
Delete All Records
To delete all the records, but keep the table, leave out the WHERE clause:
Note: SQLite has no TRUNCATE statement. A DELETE without WHERE does the same job, and SQLite makes it fast.
What Does DELETE Return?
A DELETE statement returns no rows. It only deletes the data.
When you run a DELETE in our editor, you see the message "You have made changes to the database. Rows affected: 1". That message is written by the editor, not by SQLite. It tells you how many rows were deleted.
Count the Deleted Rows
SQLite remembers how many rows the last INSERT, UPDATE or DELETE changed. The changes() function returns that number. This example deletes the customers from Mexico, and then shows how many rows were deleted:
See the Deleted Rows
Add RETURNING at the end, and the DELETE returns the deleted rows, like a SELECT:
Example
DELETE FROM Customers
WHERE Country = 'Mexico'
RETURNING CustomerName, City;
Try it Yourself »
Tip: Read more in the SQLite RETURNING chapter. In Python, cur.rowcount tells how many rows were deleted. See the Python SQLite Delete chapter.
Delete a Table
To delete the whole table, with all its records, use DROP TABLE. Read more in the SQLite Drop Table chapter.