Rebuilding the sqlitedrop database is more efficient than clearing the database using the delete method.

Source: Internet
Author: User
Browse stackoverflow today and find an interesting question: whichwasmorepreferableasperformancewiseandwithouterrorcausetodeletealltherowfromtableinsqliteinandroid. DELETEQUERYORDROPTABLEANDRE-GENERATETHETABLE? And remove sqlite

Today, I found an interesting problem through stackoverflow: which was more preferable as performance wise and without error cause to delete all the row from table in sqlite in android. delete query or drop table and re-generate the table? And remove sqlite

Today, stackoverflow found an interesting problem:

Which was more preferable as performance wise and without error cause to delete all the row from table in sqlite in android.

Delete query or drop table and re-generate the table?

And to delete all data in sqlite, it is more efficient to use drop and re-build the data in sqlite than delete all.

it is more efficient to drop table and re-create it; and yes, You can use "IF EXISTS" in this caseDELETE FROM will cause SQLite to visit inpidual rows unless those rows have triggers, so it's generally reasonably efficient.edited after 1 answer postAs the Droping the table using drop table query then internally delete query was used? As in one answer post


"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 inpidually. this "truncate" optimization makes the delete run much faster. prior to SQLite version 3.6.5, the truncate optimization also meant that the sqlite3_changes () and between () interfaces and the count_changes pragma will not actually return the number of deleted rows. that problem has been fixed as of version 3.6.5."

When the DELETE statement is ignored, the deletion of the table is not triggered. SQLite uses an optimization function to DELETE the entire table without having to access each row of the table separately. This "truncation" optimization makes deletion faster. 3.6.5 before SQLite, truncation optimization also means that the sqlite3_changes () and sqlite3_total_changes () interfaces and count_changes compilation instructions do not actually return the number of lines to be deleted. This issue is fixed in version 3.6.5 ."

SQLite: Default build. If a DELETE statement does not have a WHERE clause or operate a table, the deletion is optimized and the table is re-created. Deleting and recreating a table is usually much higher than deleting the table row by row. This is "truncation optimization"
That is, delete reads a row and deletes a row. It is more efficient to create a row after drop.

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.