如何返回最后插入的主键 [英] How to return the last primary key inserted
本文介绍了如何返回最后插入的主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要求在informix
中执行以下替代查询或类似查询:
I ask about alternative or similar query in informix
to perform the following:
INSERT INTO days (depcode,studycode,batchnum) values (1,2,3);SELECT SCOPE_IDENTITY();
我希望查询在插入语句期间返回SCOPE_IDENTITY()
I want a query to return the SCOPE_IDENTITY()
during insertion statement
推荐答案
我知道在t-sql中您有OUTPUT
语句吗?
其中[KEY]
是主键的列名,而@OUT_KEY
是您需要声明的变量
I know that in t-sql you have the OUTPUT
statement?
Where [KEY]
is the column name of your primary key and @OUT_KEY
is a variable you need to declare
INSERT INTO days
(
depcode,
studycode,
batchnum
)
OUTPUT INSERTED.[KEY] INTO @OUT_KEY
VALUES
(
1,2,3
)
编辑
对于notifyix,您可以使用
For informix you can use
SELECT DBINFO( 'sqlca.sqlerrd1' )
FROM systables
WHERE tabid = 1;
假设您的pk列为SERIAL
Presuming your pk column is SERIAL
这篇关于如何返回最后插入的主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文