http://www.sqlservercentral.com/blogs/sqlstudies/2013/02/28/insert-multiple-values-sets-into-a-table-in-one-command/

Printed 2014/08/01 11:22AM

Insert multiple values sets into a table in one command

By Kenneth Fisher, 2013/02/28

The INSERT command has two distinct ways to load data into a table.

INSERT INTO Table (field1, field2) VALUES ('string1','string2')

And

INSERT INTO Table (field1, field2)
SELECT field1, field2 FROM Table2

Both of these are very handy and have been around as far back as I can remember. Historically you would use the INSERT INTO VALUES to load one row, and the INSERT INTO SELECT to load multiple rows. However as of SQL 2008 the INSERT INTO VALUES was expanded to allow multiple inserts at once.

INSERT INTO Table (field1, field2) VALUES
     ('string1','string2'),
     ('stringA','stringB') 

This lets you create a single command that will insert multiple rows into a table at once. Basically you list multiple (valuelist)s delimited by commas. There may be a high end to the number of (valuelist)s that you can put in a single command but I haven’t found it yet.



Copyright © 2002-2014 Simple Talk Publishing. All Rights Reserved. Privacy Policy. Terms of Use. Report Abuse.