INSERT Statement


 

SQLite: INSERT Statement

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

 

Description:

SQLite tables store data in rows, one row after another. The SQLite INSERT statement is used to insert a single record or multiple records into a table in SQLite by specifying a list of values to be inserted into each table column. The arrangement of values is important on how they are arranged in the code corresponds to data values are arranged in the the SQLite table.

 

Syntax:

However, the full syntax for the SQLite INSERT statement is:

 
Note: The first form does not specify the column names where the data will be inserted, only their values, whereas the second form specifies both the column names and the values to be inserted.

 

Parameters or Arguments:

table

The table to insert the records into.

column1, column2

The columns in the table to insert values.

value1,value2

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

 

Examples:

  • The following SQLite statement insert data into employee table.

    Note: Id value as 100 in the statement, because i don’t want to start my employee id as 1 and you know why so in next example.
     
  • The following SQLite statement insert more data into employee table.

    Note: Id value this time is automatically updated with a unique number for each record in the table and continued from last statement.
     
  • The following SQLite statement will insert a new row, but only insert data in the “name” columns:

    Note: When inserting records into a table using the SQLite INSERT statement, you must provide a value for every NOT NULL column. You can omit a column from the SQLite INSERT statement if the column allows NULL values.
     
  • The following SQLite statement inset data into account table with FOREIGN KEY:

    Note: Take a look at emp_id values, it looks similar to id column values of employee table. It throws an error while you inserting some random values, rather than available values.