如何在一个语句中插入 1000 次?使用 SQLITE? [英] How do i insert 1000 times in one statement? with SQLITE?
问题描述
-edit- 为了更清楚,我只是使用了一个 cmd 行(在这种情况下实际上是 ide)并且想用 ram 进行快速测试,并且不想制作一个完整的 prj 来进行快速的一次性测试.
-edit- to make it more clear, i was just using a cmd line (actually ide in this case) and wanted to do quick testing with ram and didnt feel like making a full blown prj for a quick throwaway test.
我想用 10000000 个值填充这个表,但首先我只想要 1000 个.
I want to fill this table with 10000000 values but first i want only 1000.
我在 sqlite 数据库浏览器中尝试过这个,但没有插入 3,除非我删除它之后的所有内容.但更重要的是我不知道如何让 num 从 1 到 1000.
I tried this in sqlite database browser but 3 isnt inserted unless i drop everything after it. But more importantly i dont know how to have num go from 1 to 1000.
create table if not exists test1(id integer primary key, val integer);
insert into test1(val) select '3' as num where num between 1 and 1000
推荐答案
好的,这里有一个纯 SQL 的方法...
OK, here's a way to do it in pure SQL...
create table if not exists test1(id integer primary key, val integer);
create trigger test1_ins_trigger after insert on test1
when new.val < 1000 begin
insert into test1(val) values(new.val + 1);
end;
pragma recursive_triggers = 1;
insert into test1(val) values(1);
这篇关于如何在一个语句中插入 1000 次?使用 SQLITE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!