To insert multiple rows in SQL we can follow the below syntax:
INSERT INTO table_name (column1, column2,column3...)
VALUES
(value1, value2, value3…..),
(value1, value2, value3….),
...
(value1, value2, value3);
Employee Table
emp_id | emp_name | salary | dept_id | manager_id |
---|---|---|---|---|
E1 | Rahul | 15000 | D1 | M1 |
E2 | Manoj | 15000 | D1 | M1 |
E3 | James | 55000 | D2 | M2 |
E4 | Michael | 25000 | D2 | M2 |
E5 | Ali | 20000 | D10 | M3 |
E6 | Robin | 35000 | D10 | M3 |
We start off by giving the keywords INSERT INTO then we give the name of the table into which we would want to insert the values. We will follow it up with the list of the columns, for which we would have to add the values. Then we will give in the VALUES keyword and finally, we will give the list of values.
Here is an example of the same:
INSERT INTO Employee values
('E7', 'Ahmed', 18000, 'D2', 'M1'),
('E8', 'Zaid', 24000, 'D10', 'M2'),
('E9', 'John', 25000, 'D1', 'M2');
Select * from Employee;
Output
emp_id | emp_name | salary | dept_id | manager_id |
---|---|---|---|---|
E1 | Rahul | 15000 | D1 | M1 |
E2 | Manoj | 15000 | D1 | M1 |
E3 | James | 55000 | D2 | M2 |
E4 | Michael | 25000 | D2 | M2 |
E5 | Ali | 20000 | D10 | M3 |
E6 | Robin | 35000 | D10 | M3 |
E7 | Ahmed | 18000 | D2 | M1 |
E8 | Zaid | 24000 | D10 | M2 |
E9 | John | 25000 | D1 | M2 |
In the above example, we are inserting multiple records into the table called Employee.