5 sqlite
-edit-为了让它更清晰,我只是使用cmd线(在这种情况下实际上是ide)并且想要用ram进行快速测试并且不想为快速一次性测试制作完整的prj.
我想用10000000值填充此表,但首先我只想要1000.
我在sqlite数据库浏览器中尝试了这个但是没有插入3,除非我删除它之后的所有内容.但更重要的是,我不知道如何将num从1变为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
Run Code Online (Sandbox Code Playgroud)
Dou*_*rie 12
好的,这是在纯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);
Run Code Online (Sandbox Code Playgroud)
CREATE TEMP TABLE Bits (Bit INTEGER PRIMARY KEY);
INSERT INTO Bits VALUES (0);
INSERT INTO Bits VALUES (1);
CREATE TEMP TABLE Nums AS SELECT
b9.Bit * 512 + b8.Bit * 256 + b7.Bit * 128 + b6.Bit * 64 + b5.Bit * 32 +
b4.Bit * 16 + b3.Bit * 8 + b2.Bit * 4 + b1.Bit * 2 + b0.Bit
AS Num
FROM Bits b9, Bits b8, Bits b7, Bits b6, Bits b5,
Bits b4, Bits b3, Bits b2, Bits b1, Bits b0;
CREATE TABLE Test1 (ID INTEGER PRIMARY KEY, Val INTEGER);
INSERT INTO Test1 SELECT Num, 3 FROM Nums WHERE Num BETWEEN 1 AND 1000;
Run Code Online (Sandbox Code Playgroud)