码迷,mamicode.com
首页 > 数据库 > 详细

有关sqlitedrop数据库重建比delete方式来清空数据库更加有效率

时间:2014-11-30 22:52:21      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:android   io   os   使用   sp   for   on   数据   div   

今天浏览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?

及关于删除sqlite里面所有数据,用drop并重建比delete all sqlite里面的数据更加有效率

it is more efficient to drop table and re-create it; and yes, You can use "IF EXISTS" in this case

DELETE FROM will cause SQLite to visit individual rows unless those rows have triggers, so its generally reasonably efficient.

edited after 1 answer post

As 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 individually. 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 sqlite3_total_changes() 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."

当忽略来自DELETE语句,表被删除没有触发,SQLite使用一个优化删除整个表内容无需单独访问表的每一行。 这种“截断”优化使得删除运行更快。 3.6.5 SQLite版本之前,截断优化也意味着sqlite3_changes()和sqlite3_total_changes()接口和count_changes编译指示实际上不会返回删除的行数。 这个问题已经固定的版本3.6.5。”

SQLite它说:默认的构建,如果一个DELETE语句没有WHERE子句和运营一个表没有触发,导致删除发生发生优化删除和重新创建表。 删除和重新创建一个表通常远远高于逐行删除表的内容。 这是“截断优化”
也就是delete有读取一行删除一行的,drop后创建明显效率高些

有关sqlitedrop数据库重建比delete方式来清空数据库更加有效率

标签:android   io   os   使用   sp   for   on   数据   div   

原文地址:http://www.cnblogs.com/androidsuperman/p/4133778.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!