Inserting data
4. Insert multiple rows

Instruction

Magnificent! Now, if you need to fill up your database quickly, you may be wondering how to add a lot of data without much effort. Of course, you could write an INSERT INTO statement for each separate row, but there is also a quicker way. Have a look:

INSERT INTO user (id, name) 
VALUES (6, 'Chris'), (7, 'Barbara');

That's right, after the closing parenthesis with the values, you can put a comma and continue adding more rows in the same way. This allows you to add multiple values quickly.

Exercise

A lot of Czech tourists are now coming to the restaurant and they would like to try some of their national dishes. Let's give them

  • a main course Gulas s knedlikem (id 11, price 29), and
  • a dessert Vosi Hnizda (id 12, price 14).

 

Stuck? Here's a hint!

Type

INSERT INTO dish 
VALUES 
(11, 'main course', 'Gulas s knedlikem', 29), 
(12, 'dessert', 'Vosi Hnizda', 14);