易截截图软件、单文件、免安装、纯绿色、仅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之Database is locked问题

环境:QNX 6.3.2
版本:SQLite 2.7.3
现象:在命令行下sqlite进去,执行.table、pragma之类、select都提示
 database is locked
奇怪的是,即使是新创建一个数据库,执行上述命令也是那样。
另:在一台完 ......

sqlite数据库查询表靠前

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

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

web_news 表里有TOP列 怎样让TOP列记录为1的为置前  各位大大们帮帮忙 分不多 请包涵!!
order ......

sqlite3 linux下C语言的问题

用的是sqllite3,请问在linux先如何用C语言导出数据库啊?
"导出数据库"是是什么?

将 tab_xx 中的数据导出到文件a.txt
sqlite> .output a.txt
sqlite> select * from tab_xx;
sqli ......

SQLite有办法透过网络连接吗?

目前在公司的linux pc上有一个SQLite server, 我想用在同个区網底下的win pc去连接SQLite server用ASP進行操作, 请问有办法办到吗? 还是SQLite server无法支持网络连接....找了一个下午


剛 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号