This SQLite post explains how to use the SQLite INSERT statement with syntax and examples.
The SQLite INSERT statement is used to insert a single record or multiple records into a table in SQLite.
The syntax for the SQLite INSERT statement when inserting a single record using the VALUES keyword is:
Or...
The syntax for the INSERT statement when inserting multiple records using a sub-select in SQLite is:
The table to insert the records into.
The columns in the table to insert values.
The values to assign to the columns in the table. So column1 would be assigned the value of expression1, column2 would be assigned the value of expression2, and so on.
The source table when inserting data from another table.
Optional. The conditions that must be met for the records to be inserted.
The simplest way to create a SQLite INSERT query to list the values using the VALUES keyword.
For example:
This SQLite INSERT statement would result in one record being inserted into the employees table. This new record would have an employee_id of 1, last_name of 'Smith', first_name of 'John', and favorite_website of 'AODBA.com'.
You can also insert more than one record at a time in SQLite using the VALUES keyword. This is done by comma delimiting the records that you wish to insert.
For example:
This SQLite INSERT statement would result in two records being inserted into the employees table. The first record is identified with an employee_id of 1. All values for the first record are enclosed in parentheses.
You then separate the records with a comma and list the values for the next record which is again enclosed in parentheses.
You can also create more complicated SQLite INSERT statements using sub-selects.
For example:
By placing a SELECT statement within the INSERT statement, you can perform multiples inserts quickly.
With this type of insert, you may wish to check for the number of rows being inserted. You can determine the number of rows that will be inserted by running the following SQLite SELECT statement before performing the insert.