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.
SQLite DELETE query is used to remove existing records from a specified table. You can use the WHERE clause with DELETE queries to delete the selected rows. You have to write a table name after the DELETE FROM clause, from which you want to delete records.
SQLite allows you to drop only one table at a time. To remove multiple tables, you need to issue multiple DROP TABLE statements. If you remove a non-existing table, SQLite issues an error.
SQLite DELETE Query is used to delete the existing records from a table. You can use WHERE clause with DELETE query to delete the selected rows, otherwise all the records would be deleted.
SQLite is somewhat lazy to reclaim unused space; use the VACUUM command or auto vacuum mode. the datbase format trades space efficiency for speedy access. if you just dump the data contents, either as SQL dump or simply a CVS file for each database table, you'll likely get smaller files.
It is the two step process:
Delete all data from that table using:
Delete from TableName
Then:
DELETE FROM SQLITE_SEQUENCE WHERE name='TableName';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With