We can insert multiple rows in the SQL database using insert statement, insert into select statement, and Union All statement. Inserting multiple values in the rows is a tedious task when a table comes with a lot of attributes. In Laravel, we can add the whole array as rows and insert them in the database. We have used the DB query builder and eloquent model.
Previously, we were habituated to add values in row one at a time which is very time-taking and which also results in a lot of error. If we want to get rid of this, we are going to learn how to insert the multiple rows in a table at a time.
There are different methods to insert values in a table:
1. Using INSERT Statement.
2. Using INSERT INTO SELECT statement.
3. Using UNION ALL keyword.
INSERT INTO table_name(column1, column2, ……., column n) VALUES (values in
row 1), (values in row 2), ……… (values in row n);
#sql #sql insert multiple rows