How to delete all records from table in sqlite with Android?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
To delete all rows from a SQLite table on Android, the normal solution is either db.delete(table, null, null) or db.execSQL("DELETE FROM table"). Both remove every row because there is no WHERE clause. The practical difference is mostly API style. In Android code, delete(...) is usually clearer and safer because it avoids manually composing SQL strings.
The Straightforward Android API
If you already have a writable database from SQLiteOpenHelper, this is the most idiomatic form:
Passing null for the selection and selection arguments means "delete every row in the table."
This is usually the best answer for app code because it is explicit and easy to read.
Equivalent Raw SQL
You can do the same thing with raw SQL:
This works too, but it gives you no direct deleted-row count and is less structured than the delete(...) call.
Use raw SQL when you truly need it, not by default.
Full Example With SQLiteOpenHelper
Now the rest of the app can call clearUsers() instead of scattering delete logic around the codebase.
Use A Transaction For Multi-Step Cleanup
If table cleanup is part of a larger reset flow, wrap it in a transaction.
This matters when multiple tables must be cleared together consistently.
DELETE Is Not TRUNCATE
A common point of confusion: SQLite does not support TRUNCATE TABLE the way some other databases do. Use DELETE FROM tableName or the Android delete(...) wrapper.
If you need to reset an autoincrement sequence too, that is a separate concern. Deleting rows does not automatically guarantee the exact future ID behavior some developers expect.
Large Deletes And File Size
Deleting rows removes the data logically, but it does not necessarily shrink the database file immediately. If reclaiming disk space matters after a large cleanup, you may need VACUUM.
Do not run VACUUM casually in latency-sensitive paths. It can be expensive.
When Dropping And Recreating The Table Makes Sense
If your goal is a full reset during development or local cache rebuild, another option is dropping and recreating the table. That is heavier and more destructive than deleting rows, so it is usually best reserved for schema migration or complete local state reset logic.
If the table structure should remain the same and only the rows should go away, delete(...) is the right tool.
Common Pitfalls
- Looking for
TRUNCATE TABLEin SQLite even though SQLite usesDELETEinstead. - Building raw SQL strings unnecessarily when
db.delete(...)already expresses the operation clearly. - Forgetting transactions when clearing multiple related tables as one logical reset.
- Assuming the database file will shrink immediately after deleting rows.
- Confusing row deletion with resetting autoincrement behavior.
Summary
- On Android with SQLite, delete all rows with
db.delete("table", null, null). - '
db.execSQL("DELETE FROM table")is equivalent but usually less convenient.' - SQLite does not support
TRUNCATE TABLE. - Use transactions when clearing multiple tables together.
- If reclaiming disk space matters after large deletions, consider
VACUUMseparately.

