Insert Multiple Rows in SQL
How to Insert Multiple Rows in SQL
You can insert multiple rows into a table with a single INSERT statement by listing multiple sets of values, separated by commas.
Syntax:
INSERT INTO table_name (column1, column2, column3, ...)VALUES (value1a, value2a, value3a), (value1b, value2b, value3b), (value1c, value2c, value3c);Example:
Suppose you have a table employees with columns id, name, and department:
INSERT INTO employees (id, name, department)VALUES (1, 'Alice', 'Sales'), (2, 'Bob', 'Marketing'), (3, 'Charlie', 'IT');Notes:
All rows must have values for the specified columns.
The order and data types of values must match the columns.
This syntax is supported in most popular databases like MySQL, PostgreSQL, SQL Server, and SQLite.
If you want, I can also show how to insert multiple rows from another table or using SELECT!