Transactions and global variables  Checking IDENTITY values with @@identity

Chapter 14: Using Batches and Control-of-Flow Language

Checking for errors with @@error

The @@error global variable is commonly used to check the error status of the most recently executed batch in the current user session. @@error contains 0 if the last transaction succeeded; otherwise @@error contains the last error number generated by the system. A statement such as if @@error != 0 followed by return causes an exit on error.

Every Transact-SQL statement, including print statements and if tests, resets @@error, so the status check must immediately follow the batch whose success is in question.

The @@sqlstatus global variable has no effect on @@error output. See “Checking the status from the last fetch” for details.





Copyright © 2005. Sybase Inc. All rights reserved. Checking IDENTITY values with @@identity

View this book as PDF