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

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

insert之后,如何得到刚刚增加的值呢? 谢谢大家
...全文
35 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
every_one 2002-12-19
  • 打赏
  • 举报
回复
看看下面这段话也许对你有用==============================================
Database Connectivity Information
==============================================

New DBParm Support
==================
Support for a new DBParm, AtAtIdentity, has been added to the
Microsoft SQL Server (PBMSS70.DLL) interface.

AtAtIdentity
--------------
Specifies what syntax the Microsoft SQL Server database interface
uses to obtain the identity value of a new row in a database table.

When a DataWindow update request inserts a new row into a
Microsoft SQL Server table that contains an IDENTITY column, the
DataWindow engine calls PBMSS70 to obtain the identity value of
the newly inserted row. The AtAtIdentity DBParm allows you to
define how this request is implemented.

Values are:

0 (Default) Use the syntax SELECT MAX(IDENTCOL) FROM <table name>
to obtain the identity value of the newly inserted row

1 Use the syntax SELECT @@identity to obtain the identity value
of the newly inserted row

By default, PBMSS70 issues SELECT MAX(IDENTCOL) FROM <table name>.
This produces the correct result as long as two users are not updating
the same table at the exact same time. If your application does
many concurrent updates to the same table, set AtAtIdentity = 1.

When AtAtIdentity is set, PBMSS70 issues SELECT @@identity to obtain the
IDENTITY column value of the newly inserted row. If this request
is successful, you will have the correct identity value regardless
of concurrent updates. However, AtAtIdentity=1 may not work if the
table containing the IDENTITY column has an insert trigger associated
with it. The insert trigger may perform another database activity
(such as inserting a row in an activity log table) which causes
the @@identity system variable to be reset to zero.

For this reason, you must decide on a case-by-case basis the best
technique for obtaining newly inserted identity values.
Since AtAtIdentity is a dynamic DBParm, it can be set and reset
at any time during an application.

You can set the AtAtIdentity DBParm in the Transaction object of a
PowerBuilder application script by typing the following:
SQLCA.dbParm = "AtAtIdentity = '1'"
The AtAtIdentity DBParm cannot be set via the MSS Database Profile
Setup dialog box.


handi 2002-12-16
  • 打赏
  • 举报
回复
pfc 自己有演示程序,你可以打开看看。
dotnba 2002-12-15
  • 打赏
  • 举报
回复
我知道原因了:
在PB8中,连接属性里:Syntax:use @@identity to abtain IDENTITY column value
即加:

SQLCA.DBParm = "AtAtIdentity=1"
handi 2002-12-15
  • 打赏
  • 举报
回复
对了,我使用Dw.update insert数据库, 不知道有没有影响呢?
还有,我的自动增加字段是10位字符串,不是数字类型。


to wonder01(一可) 我试了你给我的语法,还是不行, 再帮帮忙看看还有其他办法么?谢谢。
lkcowboy 2002-12-15
  • 打赏
  • 举报
回复
up
every_one 2002-12-15
  • 打赏
  • 举报
回复
真是不好意思,我顺便问一下,如何才能让PFC运行起来?
every_one 2002-12-15
  • 打赏
  • 举报
回复
感谢,已经收到,up
handi 2002-12-15
  • 打赏
  • 举报
回复
ps: pfc已寄
handi 2002-12-15
  • 打赏
  • 举报
回复
我只插入一行,但是自动增加的那个字段不一定是最大值,因为我有很多零散的数据不是用这种方式插入的, 所以在插入之前,不知道他添加的是多少号了。
every_one 2002-12-15
  • 打赏
  • 举报
回复
handi(寒地) 兄,给我看看你的PFC吧,
daluobo@vip.sina.com
另外我看 hdyes(我插,你知道插你什么吗?) 的方法应该可以,因为你知道你要插入多少行吧,:)
handi 2002-12-15
  • 打赏
  • 举报
回复
可是我用的是pb8.03 难道是asa的问题?
ldy, 能不能给我你的email? 我给你发我的截图过去,谢谢
YewPu 2002-12-15
  • 打赏
  • 举报
回复
inser之前得到就行了。
dotnba 2002-12-15
  • 打赏
  • 举报
回复
To handi(寒地) :
这是PB8支持的,6.5没有这个选项
DB Profile
DataBase Profile Setup --> Syntax
muse_123 2002-12-15
  • 打赏
  • 举报
回复
UP
handi 2002-12-15
  • 打赏
  • 举报
回复
to ldy: 是不是profile painter中? 找不到这个属性啊。我直接加到SQLCA.DBParm中,虽然没有报错,可是情况依旧...
handi 2002-12-14
  • 打赏
  • 举报
回复
但是我提出的@@identity是0, 不知道是不是桌面版的原因。..还有没有更好的办法呢?谢谢大家。
对了,谁要我修改的pfc? mail我。
handi@sina.com
banalman 2002-12-14
  • 打赏
  • 举报
回复
同意 ldy(罗大佑)
dotnba 2002-12-14
  • 打赏
  • 举报
回复
根据这个(On each subsequent insert, the value of the column increases by one),我想新插入的行应该是最大的!
在你插入后马上取出,应该得到
dotnba 2002-12-14
  • 打赏
  • 举报
回复
The first time you insert a row into the table, an IDENTITY column has a value of 1 assigned to it. On each subsequent insert, the value of the column increases by one. The value most recently inserted into an identity column is available in the @@identity global variable.

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

DECLARE my_cursor CURSOR FOR
select @@IDENTITY;

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

OPEN my_cursor;
FETCH my_cursor INTO :ll_IDENTITY; //获得自增长序列的值
接着,我就等着接分了!
加载更多回复(3)

1,075

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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