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

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



相关问答:

使用飞信虚拟.net环境,在使用SQLite时为什么报错呢

C# code:

System.Data.SQLite.SQLiteConnection conn = new SQLiteConnection(@"acs.db");
try
{
conn.Open();
}
......

SQlite的一个问题

如下语句 :
select TimeSpan from T_Table where onlineDate = '2009-12-2'
数据库里面有符合条件的值但是查不出来
如果改成如下:
select TimeSpan from T_Table where onlineDate = '200 ......

有关SQlite的一个问题

程序代码如下:
sqlTime = "select SUM(onlineTimeSpan) from T_OnlineTimeSum where ipAddress = :a AND onlineDate BETWEEN :b AND :c";
                ......

求高手指点,一个PDA程序,sqlite数据库连接不上,急

string ConStr="data source=C:\ceshi.db;verson=3;password=123456";
  SQLiteConnection MyConnection = new SQLiteConnection(ConStr);
  try
  { ......

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 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号