SQLite Insert

SQLite has a very simple syntax for inserting data into a table. SQLite INSERT statement is used to insert data into a table.

Syntax

INSERT INTO table_name (column1, column2)
VALUES (value1, value2);

Example

The following example shows how to insert a new row into the “customers” table:

INSERT INTO customers (first_name, last_name)
VALUES ('John', 'Smith');

You can also use the SQLite insert into command to insert data into a table from another table.

INSERT INTO table_b (column1, column2, column3)
SELECT column1, column2, column3
FROM table_a;

For example, the following SQLite insert into command would insert all rows from the “customers” table into the “contacts” table:

INSERT INTO contacts (first_name, last_name, address)
SELECT first_name, last_name, address
FROM customers;

You can also use the SQLite insert into command to insert multiple rows into a table.
To do this, you need to use the SQLite INSERT INTO command followed by the VALUES clause. The VALUES clause can contain multiple sets of values, each set enclosed in parentheses and separated by commas.

INSERT INTO table_name (col1, col2, col3)
VALUES ('a1', 'a2', 'a3'), 
('b1', 'b2', 'b3');

For example, the following SQLite insert into command would insert two new rows into the “customers” table:

INSERT INTO customers (first_name, last_name, address)
VALUES ('John', 'Smith', 'New York'),
('Jane', 'Doe', 'Los Angeles');