How to Insert Several Rows at Once in SQLite
Adding rows one INSERT at a time works, but one INSERT can add many: list one set of values per row after VALUES. This guide adds three books in one statement, with real output from SQLite 3.54.1.
Syntax
INSERT INTO <table> (<column 1>, <column 2>) VALUES
(<value 1>, <value 2>),
(<value 1>, <value 2>);
| Part | What it means |
|---|---|
(<value 1>, <value 2>) | One list of values for each new row, in the order of the column list |
, between the lists | Separates the rows. Only the last list is followed by ; |
SQLite's documentation on INSERT: "The first form (with the "VALUES" keyword) creates one or more new rows in an existing table."
Prerequisites
- The sqlite3 command-line shell. This guide uses SQLite 3.54.1. Run
sqlite3 --versionto see yours; the SQLite download page has the command-line tools for Windows, macOS and Linux.
Step 1: Write the Script
Save this as insert_rows.sql:
CREATE TABLE books (
title TEXT NOT NULL,
pages INTEGER NOT NULL
);
INSERT INTO books (title, pages) VALUES
('Emma', 474),
('Persuasion', 249),
('Dune', 412);
SELECT * FROM books;

- One
INSERTnames the columns once, then gives three value lists, one per book. - A comma separates the lists, and the semicolon comes after the last one.
Step 2: Run It
In the folder that holds the script, run:
sqlite3 -table library.db ".read insert_rows.sql"
sqlite3 opens the database file library.db, and creates it when it isn't there. -table prints each result as a table, and .read runs the statements in the script. The command is the same in bash, zsh and PowerShell.
+------------+-------+
| title | pages |
+------------+-------+
| Emma | 474 |
| Persuasion | 249 |
| Dune | 412 |
+------------+-------+

One statement added all three books, in the order of the lists.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
| A semicolon after each list | The first semicolon ends the statement, and the next line fails with near "(": syntax error | Commas between the lists, one semicolon at the end |
A list with a value missing, such as ('Persuasion') | all VALUES must have the same number of terms | Give every list one value per column |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
NOT NULL constraint failed: books.title, and no rows added | One list broke a rule, so the whole statement was undone | Fix that list and run the statement again |
Parse error near line 1 of insert_rows.sql: table books already exists | The script already ran on library.db | Delete library.db and run the script again |
FAQ
What happens when one row breaks a rule?
None of the rows go in. With a NULL title in the middle list, the statement failed with NOT NULL constraint failed: books.title, and the table stayed empty, Emma included. SQLite's documentation on conflicts: the default response "aborts the current SQL statement with an SQLITE_CONSTRAINT error and backs out any changes made by the current SQL statement".
Is one INSERT with many rows different from many INSERTs?
The rows end up the same. The difference is what a failure undoes: one statement is all or nothing, while separate INSERT statements each succeed or fail on their own.
Conclusion
One INSERT with three value lists added Emma, Persuasion and Dune together, and a bad row in the middle would have kept all three out.
Additional Resources
- INSERT — every form of the statement.
- ON CONFLICT — what SQLite undoes when a row breaks a constraint.
