易截截图软件、单文件、免安装、纯绿色、仅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 的回复:
呵呵,不能,测试了一下不行

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



相关问答:

wince下使用sqlite的快速查询?

大家好:
      最近在wince下使用sqlite,但是由于表的内容量大,所以查询效率很低,不知道什么问题及怎么解决。
      我的表的结构如下:
      name&nbs ......

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_prepare 这个函数 select 就好使 只要 改变数据库 的就不行 比如insert 之类的 谁来帮个忙啊 请问这是什么原因 啊 用 c 去实现的
你用的什么工具啊?
把你自己的代码发 ......

flex air连接sqlite查询报错:no such table

XML code:
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx ......

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号