UPDATE Statement


 

 

SQLite: UPDATE Statement

This SQLite tutorial explains how to use the SQLite UPDATE statement with syntax and examples.

 

Description:

The SQLite UPDATE statement is used to update/modify existing records in a table in a SQLite database. There are 2 syntaxes for the UPDATE statement depending on the type of update that you wish to perform.

 

Syntax:

In its simplest form, the syntax for the SQLite UPDATE statement when updating one table is:

Note: UPDATE Statement uses WHERE clause. The WHERE clause specifies which record or records that should be updated. If you omit the WHERE clause, all records will be updated!

However, the full syntax for the SQLite UPDATE statement when updating one table is:

 
Parameters or Arguments:

table

The name of the table that you wish to update.

column1, column2

The columns that you wish to update.

value1, value2

The new values to assign to the column1, column2. So column1 would be assigned the value of value1, column2 would be assigned the value of value2, and so on.

conditions

The conditions that must be met for the update to execute.

ORDER BY

Optional. It may be used in combination with LIMIT to sort the records appropriately when limiting the number of records to be updated.

LIMIT

Optional. If LIMIT is provided, it controls the maximum number of records to update in the table. At most, the number of records specified by number_rows will be update in the table. The first row selected by LIMIT will be determined by offset_value.

 

Examples:

  • The following SQLite statement, which would update the employee “anitha” with a new position.

    id name position hire_date
    100 chiru developer 1/1/2014
    101 arunesh manager 1/1/2012
    102 naga Team Lead 1/1/2013
    103 nithya developer 6/1/2013
    104 jaya developer 1/1/2014
    105 uma designer 1/1/2013
    106 mathu research analyst 1/1/2013
    107 anitha research analyst 1/1/2014
    108 kannan 6/1/2013
    109 deepak
  • Update Warning!
    Be careful when updating records. If we had omitted the WHERE clause, in the example above, like this:

    id name position hire_date
    100 chiru Team Lead 1/1/2014
    101 arunesh Team Lead 1/1/2012
    102 naga Team Lead 1/1/2013
    103 nithya Team Lead 6/1/2013
    104 jaya Team Lead 1/1/2014
    105 uma Team Lead 1/1/2013
    106 mathu Team Lead 1/1/2013
    107 anitha Team Lead 1/1/2014
    108 kannan Team Lead 6/1/2013
    109 deepak Team Lead