sqlite 中
CREATE TABLE table1 (
id integer primary key autoincrement,
name text default '',
[index] integer default ROWID
)
有没有类似的功能,让 index 的值默认等于id,比如
insert into table1 (id,name) values (null,'第一行');
insert into table1 (id,name) values (null,'第二行');
我希望结果是
id name index
1 第一行 1
2 第二行 2
能实现吗?
引用 CREATE TABLE table1 ( id integer primary key autoincrement, name text default '', [index] integer ) trigger: Begin Transaction; Drop Trigger If Exists MAIN.[dd]; Create Trigger MAIN.[dd] AFTER INSERT On [table1b] FOR EACH ROW begin update table1b set 'index'=id where id=new.id ; end; Commit Transaction; insert into table1 (id,name) values (null,'第一行'); insert into table1 (id,name) values (null,'第二行'); 一定要用到触发器和存储过程吗?不能直接设置成默认值吗
呵呵,不能,测试了一下不行
引用 呵呵,不能,测试了一下不行 嗯,知道了,果然是不行的
测试可以这样 :
insert into table1c values (null,'第一行',(select rowid from table1c));
引用 引用 3 楼 wwwwb 的回复: 呵呵,不能,测试了一下不行 嗯,知道了,果然是不行的
相关问答:
偶想备份数据表,写了一个批处理,有现成的数据库。但是批处理写到一半不会了,还请帮忙看看,怎么往下。。。 @echo off echo 正在系统数据库备份,请稍 ......
大家好: 最近在wince下使用sqlite,但是由于表的内容量大,所以查询效率很低,不知道什么问题及怎么解决。 我的表的结构如下: name&nbs ......
在vs2005中引用了using System.Data.SQLite; 定义了一个连数据库连接变量public SQLiteConnection dBConn; 就报下面这个错误了. The type 'System.Data.Common.DbConnection' is defined in an ass ......
sqlite的空值查询怎么写,能者得分 select * from tt where f1 is null select * from yourTable where col is null; SQL code: sqlite> create table Aoqun (id int primary key,col1 int); sqlite> ......