5

Is it possible to insert multiple sets of values to a SQLite table in one statement?

I was trying:

INSERT INTO the_table VALUES (1,2,'hi'),(2,0,'foo');

with the different ()s representing different insert sets, but I get an error.

1
  • 1
    Posting the error message will give you better answers. Commented May 30, 2009 at 8:44

3 Answers 3

6

Are there only three columns in your table? If not, you could try defining the column names you are setting like so:

INSERT INTO the_table 
       (column1  ,column2  ,column3) 
VALUES (1        ,2        ,'hi'   )
      ,(2        ,0        ,'foo'  )

This convention was introduced in SQL Server 2008 known as the Table Value Constructor. See MSDN's INSERT page for a look at the overall syntax. Also, the INSERT statement can be easily formatted for better readability.

Sign up to request clarification or add additional context in comments.

1 Comment

If you're going to downvote me, could you at least comment as to why this is incorrect?
1

You can do

INSERT INTO the_table 
SELECT 1,2,'hi'
UNION
SELECT 2,0,'foo';

Comments

0

I was found that syntax in MSDN but after trying I can't do that too, than I note that in the bottom of the page was written that there is an error in the page :) where is link http://msdn.microsoft.com/en-us/library/ms174335.aspx see the bottom How to insert multiple rows

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.