Reputation: 16609
in my application I have to delete whole contents of a table and refill it many times
in that case I have two solutions :
1- drop , recreat and fill the table
"DROP TABLE IF EXISTS TABLE_NAME"
2- remove all its contents and refill it
"DELETE FROM TABLE_NAME"
now which solution more effective?
Upvotes: 4
Views: 2988
Reputation: 33954
Regardless what you do, if you have any foreign keys pointing to this table be careful not to completely fubar those references.
Upvotes: 5
Reputation:
From http://www.sqlite.org/lang_delete.html :
The Truncate Optimization
When the WHERE is omitted from a DELETE statement and the table being deleted has no triggers, SQLite uses an optimization to erase the entire table content without having to visit each row of the table individually. This "truncate" optimization makes the delete run much faster.
Upvotes: 8