Page 1 of 1

how to Insert more than one row into a table in one SQL Server query?

Posted: Thu Jul 18, 2019 4:35 pm
by LDogg
how can i Insert more than one row into a table in one SQL Server query?

For example i have 5 rows i want to insert into my customers table below:

The columns are Name and Age, how can i do all of this in one SQL Server statement?

Code: Select all

INSERT INTO dbo.Customers VALUES ("Liam", 34);
INSERT INTO dbo.Customers VALUES ("Dave", 21);
INSERT INTO dbo.Customers VALUES ("Janice", 54);
INSERT INTO dbo.Customers VALUES ("Fred", 23);
INSERT INTO dbo.Customers VALUES ("Mave", 65);

Re: how to Insert more than one row into a table in one SQL Server query?

Posted: Thu Jul 18, 2019 4:47 pm
by dbaFD
You can separate the VALUES using commas in one INSERT statement.

Code: Select all

INSERT INTO dbo.customers(Name, Age) 
VALUES
  ( "Liam", 34)
, ( "Dave", 21)
, ( "Janice", 54)
, ( "Fred", 23)
, ( "Mave", 65)