SQL Insert Multiple Rows in One Statement example

What is the SQL INSERT Statement and how it can be used with the database?

The SQL INSERT statemet is used to insert new data in to the database. 

SQL MULTIPLE INSERT Statement Example: 

Assume that you have a table 'customer' in your database.

 

idnameaddressemailphone
1 Jwalant 123 xyz street jwalanttest@test.com 123-456-7890
2 Piyush 456 abc street piyushtest@test.com 123-456-7890
3 Hiren 789 pqr street hirentest@test.com 123-456-7890

 

Case 1: You just want to add new customer to the database. You have following columns on the table: name, email, phone. Use following syntax of sql insert statement for that case:

          INSERT INTO customer (name, address, email, phone) 
           VALUES ('Yogesh', '123 abc street', 'yogeshtest@test.com', '123-456-7890'), 
                      ('Vipul', '456 pqr street', 'vipultest@test.com', '123-456-7890'),
                      ('Manoj', '789 xyz street', 'manojtest@test.com', '123-456-7890');


  1. As you can see above, Insert SQL Statement starts with "INSERT INTO" followed by table name (customer in this case).
  2. Table name is followed by comma separated database table columns enclosed in the bracket.
  3. Column names are followed by keyword "VALUES".
  4. "VALUES" is followed by value of each column in order specified in the column name brackets. Each value must be within single quote, if type is String. All column values are separated by comma.

 Result:

idnameaddressemailphone
1 Jwalant 123 xyz street jwalanttest@test.com 123-456-7890
2 Piyush 456 abc street piyushtest@test.com 123-456-7890
3 Hiren 789 pqr street hirentest@test.com 123-456-7890
4 Yogesh 123 abc street yogeshtest@test.com 123-456-7890
5 Vipul 456 pqr street vipultest@test.com 123-456-7890
6 Manoj 789 xyz street manojtest@test.com 123-456-7890