SQL Server - Insert multiple rows in a query



Let’s suppose the next scenario. You have a country table with 2 columns (country_id, name) and you want to insert multiple sets of data. Instead of running multiple queries like:

 INSERT INTO country VALUES (1, 'Canada');
 INSERT INTO country VALUES (2, 'Argentina');
 INSERT INTO country VALUES (3, 'Mexico');
 INSERT INTO country VALUES (4, 'Spain');

You can run a single query that will insert multiple rows at once. The query looks like this:

INSERT INTO Table ( Column1, Column2 ) VALUES
( Value1, Value2 ), ( Value1, Value2 )

Transforming it to my country example:

INSERT INTO country ( country_id, name ) VALUES
(1, 'Canada'), 
(2, 'Argetina'),
(3, 'Mexico'),
(4, 'Spain');