易截截图软件、单文件、免安装、纯绿色、仅160KB

sqlite 字段默认值等于id值

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 的回复:
呵呵,不能,测试了一下不行

嗯,知道了,果然是不行的



相关问答:

sqlite移植问题

我现在手头有这么一个问题,我想让一个操作sqlite3的程序在一个ARM板子上跑起来,板子上的os是wince5.0。
我是这么做的,我先从sqlite3主页下载源码下来,有这么3个文件:sqlite3.c、sqlite3.h、sqlite3ext.h , ......

sqlite的空值查询怎么写,能者得分

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> ......

用过sqlite的朋友看下

最简单的问题。也有点郁闷。
我想创建一个数据库
我现在只有一个sqlite3.exe文件。
我使用的方法是双击这个文件
使用的命令为:
sqlite3 f:\a.db 回车
可是结果却显示为
  ...>
sqli ......

sqlite数据库查询表靠前

刚入门 想实现新闻表新闻置顶的功能

select * from web_news  order by id desc limit 0,6

web_news 表里有TOP列 怎样让TOP列记录为1的为置前  各位大大们帮帮忙 分不多 请包涵!!
order ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号