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

All topics about programming / development in T-SQL or other languages for SQL Server.
Post Reply
LDogg
Posts: 1
Joined: Thu Jul 18, 2019 4:30 pm

Thu Jul 18, 2019 4:35 pm

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);
dbaFD
Posts: 1
Joined: Thu Jul 18, 2019 4:37 pm

Thu Jul 18, 2019 4:47 pm

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)
Post Reply

Social Media