Blog Post

Insert multiple values sets into a table in one command

,

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.

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating