@@ERROR 在 SQL Server 2005 中 [英] @@ERROR in SQL Server 2005
问题描述
我已经学会了使用 SCOPE_IDENTITY()
而不是 @@IDENTITY
来获取给定范围中插入的最后一个标识值,这在以下情况下非常有用高并发场景.@@ERROR 变量是否有与该函数等效的函数?我的意思是,有没有办法确保每当我写
I have learned to use the SCOPE_IDENTITY()
instead of just @@IDENTITY
to get the last identity value inserted in a given scope, which can be quite useful in high-concurrency scenarios. Is there any equivalent to that function for the @@ERROR variable? I mean, is there any way to make sure that whenever I write
IF (@@ERROR <> 0) RETURN
我实际上是在强制函数返回,因为此范围内的最后一个命令导致了错误?
I am in fact forcing the function to return because of the very last command in this scope caused an error?
推荐答案
来自在线图书:
@@ERROR 只返回错误信息紧接在 Transact-SQL 之后产生错误的语句.
@@ERROR only returns error information immediately after the Transact-SQL statement that generates the error.
@@Error 仅在当前范围内.所以它应该有任何将 proc 发送到 catch 块的值,无论几个语句中的哪一个是错误的.
@@Error is only within the current scope. So it should have the value for whatever sent the proc to the catch block no matter which of several statements was the one that errored.
这篇关于@@ERROR 在 SQL Server 2005 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!