How to update first n records in SQLite

Is there any query to update only the first n SQLite DB .. records?

+3
source share
2 answers

The previous answer assumes that the primary key identifier begins with 1. This would not be the case if the rows were deleted.

http://www.sqlite.org/lang_update.html : "If SQLite is built with the SQLITE_ENABLE_UPDATE_DELETE_LIMIT compilation parameter, then the syntax of the UPDATE statement extends with the optional ORDER BY and LIMIT clauses ..."

In this case, you can use this simple query:

UPDATE table SET columns = 'value' WHERE 1 LIMIT n ORDER BY identifier ASC

Another suggestion may not be needed based on the default ordering scheme.

+6
source

int, UPDATE table SET columns = 'value' WHERE identifier <= n

+1

Source: https://habr.com/ru/post/1713023/


All Articles