Part 2 of 5 · 1 min read
Inserting multiple rows
One INSERT statement adding several rows at once.
Think of filing ten new forms into a cabinet in one trip, rather than walking back and forth ten separate times.
In plain words: a single INSERT statement can supply more than one row of values, separated by commas. This is both less code and, in most databases, meaningfully faster than running ten separate single-row INSERT statements, since it avoids repeating the overhead of starting each statement separately.
A worked example. Adding three new books in one statement.
The key lines.
INSERT INTO books (book_id, title, author_id, price) VALUES
(101, 'Clear Thinking', 12, 450.00),
(102, 'Deep Work Habits', 12, 399.00),
(103, 'The Quiet Edge', 15, 525.00);
Multi-row INSERT
A multi-row INSERT supplies several rows' worth of values in a single VALUES clause, each row's values in its own parentheses, separated by commas.
Example: the statement above adds three books in one round trip to the database, instead of three.