How to insert multiple rows?

0123

To insert multiple rows into a MySQL table, you can use a single INSERT statement with multiple sets of values. The syntax is as follows:

INSERT INTO table_name (column1, column2, column3, ...)
VALUES 
(value1a, value2a, value3a, ...),
(value1b, value2b, value3b, ...),
(value1c, value2c, value3c, ...);

Here’s an example using a products table with columns product_id, product_name, price, and quantity:

INSERT INTO products (product_id, product_name, price, quantity)
VALUES 
(1, 'Laptop', 999.99, 50),
(2, 'Smartphone', 599.99, 75),
(3, 'Tablet', 299.99, 100);

This query inserts three new rows into the products table in a single operation. Each set of values corresponds to a new row in the table.

0 Comments

no data
Be the first to share your comment!