Insert Multiple Items in One Line with MSSQL 2008

Are you tired of the amount of boiler plate code when inserting multiple records into a SQL table?

INSERT INTO Customer (Name, ID)
VALUES ('John', 1)

INSERT INTO Customer (Name, ID)
VALUES ('Kent', 2)

INSERT INTO Customer (Name, ID)
VALUES ('Dave', 3)

INSERT INTO Customer (Name, ID)
VALUES ('Jane', 4)

INSERT INTO Customer (Name, ID)
VALUES ('Anna', 5)

Yeah, me too. Fortunately for us Microsoft SQL Server 2008 and higher allows you to do it in one line.

INSERT INTO Customer (Name, ID)
VALUES ('John', 1),
         ('Kent', 2),
         ('Dave', 3),
         ('Jane', 4),
         ('Anna', 5)

Pretty cool feature that I wasn’t aware of for a very long time. It could save me quite a lot of typing.


Would you like to get the most interesting content about C# every Monday?
Sign up to C# Digest and stay up to date!