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

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

    Alex is correct: the "select ... union" statement will lose the ordering which is very important for some users. Even when you insert in a specific order, sqlite changes things so prefer to use transactions if insert ordering is important.

    create table t_example (qid int not null, primary key (qid));
    begin transaction;
    insert into "t_example" (qid) values (8);
    insert into "t_example" (qid) values (4);
    insert into "t_example" (qid) values (9);
    end transaction;    
    
    select rowid,* from t_example;
    1|8
    2|4
    3|9
    

提交回复
热议问题