About Sqlitedrop database rebuild is more efficient than delete mode to empty the database

Source: Internet
Author: User

Browse StackOverflow today to find an interesting question:

Which is more preferable as performance wise and without error cause to delete all the row from table in SQLite in Androi D.

DELETE QUERY OR DROP TABLE and re-generate the table?

And about deleting all the data in SQLite, with drop and rebuild than delete all SQLite inside the data more effective rate

ItIsMore efficientTo Drop Table andRe-create it; andYes,You canUse "IF EXISTS" InchThisCaseDELETE Fromwould cause SQLiteToVisit individualRowsunless those rows has triggers, so it's generally reasonably efficient.  Edited after 1 answer post as the droping the table using drop table Query then internally Delete query is used?  As in one   answer post             


"When the WHERE was omitted from a DELETE statement and the table being deleted have no triggers, SQLite uses an optimizatio N to erase the entire table content without have to visit each row of the table individually. This "truncate" optimization makes the delete run much faster. Prior to SQLite version 3.6.5, the truncate optimization also meant, the Sqlite3_changes () and Sqlite3_total_changes () Interfaces and the count_changes pragma would not actually return the number of deleted rows. That problem has been fixed as of version 3.6.5. "

When ignoring from the DELETE statement, the table is deleted without triggering, and SQLite uses an optimization to delete the entire table content without having to access each row of the table separately. This "truncation" optimization makes the deletion run faster. Prior to the 3.6.5 SQLite version, truncation optimizations also meant that the sqlite3_changes () and Sqlite3_total_changes () interfaces and count_changes compilation instructions did not actually return the number of deleted rows. This issue has been fixed in version 3.6.5. ”

SQLite it says: The default build, if a DELETE statement does not have a WHERE clause and the operation of a table without triggering, causes the deletion to occur when the optimization is deleted and the table is recreated. Deleting and recreating a table is usually much higher than the content of a row-wise delete table. This is "truncated optimization"
That is, delete has read a row to delete a row, the drop after the creation of significantly higher efficiency

About Sqlitedrop database rebuild is more efficient than delete mode to empty the database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.