Skip to main content

How do you insert several rows in one query?

In SQL, several rows can be added in a single query with INSERT INTO, by listing values separated by commas.

Syntax:

sql
INSERT INTO Table_Name (Field1, Field2, ..., FieldN) VALUES (Value1_1, Value1_2, ..., Value1_N), (Value2_1, Value2_2, ..., Value2_N), ...;

Example:

sql
INSERT INTO Employees (ID, Name, Age, DepartmentID) VALUES (1, 'Ivan', 30, 101), (2, 'Maria', 25, 102), (3, 'Oleksii', 40, 101);

Explanation:

  • Every pair of parentheses (…) is a new record that will be added to the table.
  • Every record gets inserted in a single query, which is faster and more efficient than running several separate INSERTs.
  • The fields must match in count and data type across every row.

Put simply, this approach lets you add several records to a table in a single action.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.