如何得到自动增加数列的值?

handi 2002-12-14 02:54:34
我用的是Sybase ASA 7.0 桌面版

insert之后,如何得到刚刚增加的值呢? 谢谢大家
...全文
84 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
dotnba 2002-12-15
  • 打赏
  • 举报
回复
在PB8中,连接属性里:Syntax:use @@identity to abtain IDENTITY column value
即加:

SQLCA.DBParm = "AtAtIdentity=1"
winnerjoanna 2002-12-15
  • 打赏
  • 举报
回复
用select max(id ) from tablename也不行吗,
那这样你试试可以吧:
int i
i=dw_1.getitemnumber(dw_1.rowcount(),"id")
handi 2002-12-14
  • 打赏
  • 举报
回复
我也看了这个帮助,我已经找这个方法把那个字段设置为IDENTITY类型的,他也自动转化为自动增加类型,可是还是不行啊。

几位高手帮帮忙。
wonder01 2002-12-14
  • 打赏
  • 举报
回复
我觉得你的分数应该给我,我经常这样做,百分百保证正确,方法如下:

DECLARE my_cursor CURSOR FOR
select @@IDENTITY;

insert into ……//执行插入操作

OPEN my_cursor;
FETCH my_cursor INTO :ll_IDENTITY; //获得自增长序列的值
dotnba 2002-12-14
  • 打赏
  • 举报
回复
看了帮助
The @@identity variable holds the most recent value inserted into an IDENTITY column or a DEFAULT AUTOINCREMENT column, or zero if the most recent insert was into a table that had no such column.

The value of @@identity is reset each time a row is inserted into a table. If a statement inserts multiple rows, @@identity reflects the IDENTITY value for the last row inserted. If the affected table does not contain an IDENTITY column, @@ identity is set to 0.

The value of @@identity is not affected by the failure of an INSERT or SELECT INTO statement, or the rollback of the transaction that contained it. @@identity retains the last value inserted into an IDENTITY column, even if the statement that inserted it fails to commit.

handi 2002-12-14
  • 打赏
  • 举报
回复
1. 那个字段不一定是我数据库中最大的值啊。
2. 我用select @@IDENTITY取出来为0, 他也的确说了兼容这个全局变量。

大家看看还有其他办法吗?谢谢大家
flyhot 2002-12-14
  • 打赏
  • 举报
回复
agree!!
愉快的登山者 2002-12-14
  • 打赏
  • 举报
回复
select max(id) from tablename
dotnba 2002-12-14
  • 打赏
  • 举报
回复
sql server中:
select @@IDENTITY
dotnba 2002-12-14
  • 打赏
  • 举报
回复
select max(identity_col) from table

754

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧