SQL: Insert multiple sets of values โ€‹โ€‹into a single statement?

Can I insert multiple sets of values โ€‹โ€‹into an SQLite table in a single expression?

I have tried:

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

with different () s representing different inserts, but I get an error.

+4
source share
3 answers

Are there only three columns in your table? If not, you can try to determine the column names that you specify this way:

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

This convention was introduced in SQL Server 2008, known as Table Value Designer . See the MSDN INSERT Page for a general syntax. In addition, the INSERT can be easily formatted for better readability.

+6
source

You can do

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

I found this syntax on MSDN, but after trying I canโ€™t do it either, than I noticed that it was written at the bottom of the page that there is an error on the page :) where is the link http://msdn.microsoft.com/en- us / library / ms174335.aspx see below How to insert multiple lines

0
source

All Articles