SQL Server
INSERT INTO customers (email) VALUES
('[email protected]'),
('[email protected]'),
('[email protected]');
Up to 1000 row-value expressions per INSERT; beyond that, switch to INSERT ... SELECT.
One round trip, many rows: the VALUES list that is a one-liner everywhere except older Oracle.
Filed under Inserting & updating
SQL Server, PostgreSQL, MySQL, SQLite and Oracle 23ai share identical syntax. Older Oracle needs INSERT … SELECT … FROM dual UNION ALL, which is wordier but does the same job in one statement.
Listing several row tuples in one VALUES clause is the normal way to batch small inserts. Oracle accepted it only from 23ai; earlier versions need INSERT ALL or a SELECT-based insert. Each engine also caps the statement in its own way, covered in bulk-insert-limits.
INSERT INTO customers (email) VALUES
('[email protected]'),
('[email protected]'),
('[email protected]');
Up to 1000 row-value expressions per INSERT; beyond that, switch to INSERT ... SELECT.
INSERT INTO customers (email) VALUES
('[email protected]'),
('[email protected]'),
('[email protected]');
No fixed row cap; the practical limit is the parameter count if you parameterize each value.
INSERT INTO customers (email) VALUES
('[email protected]'),
('[email protected]'),
('[email protected]');
Statement size is bounded by max_allowed_packet; ON DUPLICATE KEY UPDATE applies per row.
INSERT INTO customers (email) VALUES
('[email protected]'),
('[email protected]'),
('[email protected]');
Multi-row VALUES since 3.7.11. Bound parameters count against SQLITE_MAX_VARIABLE_NUMBER: 999 before 3.32, 32,766 since.
INSERT INTO customers (email)
SELECT '[email protected]' FROM dual UNION ALL
SELECT '[email protected]' FROM dual UNION ALL
SELECT '[email protected]' FROM dual;
Works on every version. 23ai also accepts the multi-row VALUES list used by the other four. INSERT ALL is the other classic form, but it generates one identity or sequence value per source row, so three branches into a table with an identity key collide.
A few hundred to a few thousand is comfortable on every engine, and SQL Server stops at 1,000. Beyond that, statement size limits and parse time make a bulk loader or INSERT … SELECT from a staging table the better tool.
INSERT ALL INTO t VALUES (…) INTO t VALUES (…) SELECT * FROM dual is a multi-table insert driven by a subquery: each INTO branch runs once per row the subquery returns, and dual has one row. Because identity and NEXTVAL values are generated once per source row, every branch gets the same id, and inserts into an identity-keyed table fail with ORA-00001.
Yes on transactional tables: it is one statement, so a failing row (say, a duplicate key) rolls back the whole insert. MySQL's INSERT IGNORE turns such errors into warnings and skips the bad rows instead.
The most portable statement in SQL: copy rows from one table into another in a single statement.
Every engine caps a single INSERT somewhere. Here is where the ceilings are.
Change the row if it is already there, insert it if it is not: the statement every engine spells differently.
SQLly is a native SQL workbench for macOS, Windows and Linux. Its formatter and plan viewer work in all five dialects.