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

后端 未结 24 2861
猫巷女王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:46

    You can't but I don't think you miss anything.

    Because you call sqlite always in process, it almost doesn't matter in performance whether you execute 1 insert statement or 100 insert statements. The commit however takes a lot of time so put those 100 inserts inside a transaction.

    Sqlite is much faster when you use parameterized queries (far less parsing needed) so I wouldn't concatenate big statements like this:

    insert into mytable (col1, col2)
    select 'a','b'
    union 
    select 'c','d'
    union ...
    

    They need to be parsed again and again because every concatenated statement is different.

提交回复
热议问题