DELETE FROM tab WHERE rowid in (SELECT rowid from tab ORDER BY … LIMIT 1000);

If SQLite compiled with SQLITE_ENABLE_UPDATE_DELETE_LIMIT  
http://www.sqlite.org/compile.html#enable_update_delete_limit

DELETE FROM tab WHERE … ORDER BY … LIMIT 1000;

From: Simon Slavin<mailto:slav...@bigfraud.org>
Sent: 2016年9月9日 23:33
To: SQLite mailing list<mailto:sqlite-users@mailinglists.sqlite.org>
Subject: Re: [sqlite] sqlite - Delete large table in sqlite


On 9 Sep 2016, at 6:14pm, Венцислав Русев <ven...@proxima-3.com> wrote:

> I don't know if this will work for you, but can't you delete 1000 rows then 
> another 1000 ... until the table is empty.

If you do do that, each 1000 rows should be deleted inside a transaction.  So

BEGIN
DELETE FROM myTable WHERE ...
END

But SQLite has an optimization in for deleting all rows of a table

DELETE FROM myTable    // no "WHERE" clause

which should mean it's faster to do it that way.

Simon.
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to