Is it possible to insert multiple rows at a time in an SQLite database?

后端 未结 24 2950
猫巷女王i
猫巷女王i 2020-11-21 06:12

In MySQL you can insert multiple rows like this:

INSERT INTO \'tablename\' (\'column1\', \'column2\') VALUES
    (\'data1\', \'data2\'),
    (\'data1\', \'da         


        
24条回答
  •  时光取名叫无心
    2020-11-21 06:41

    Yes it is possible, but not with the usual comma-separated insert values.

    Try this...

    insert into myTable (col1,col2) 
         select aValue as col1,anotherValue as col2 
         union select moreValue,evenMoreValue 
         union...
    

    Yes, it's a little ugly but easy enough to automate the generation of the statement from a set of values. Also, it appears you only need to declare the column names in the first select.

提交回复
热议问题