sqlite

Truncate a SQLite table if it exists?


To truncate a table in SQLite I need to use this syntax:

DELETE FROM someTable

But how do I truncate the table only if it exists?

Unfortunately this throws an error:

DELETE FROM someTable IF EXISTS

This doesn't work either:

DELETE IF EXISTS FROM someTable

Thanks.


Solution

  • IMHO, it is more efficient to drop the table and re-create it. And yes, you can use "IF EXISTS" in this case.