1. | How can you tell SQL Server to roll back a transaction in case an error occurs? |
|
2. | What is the difference between the functions @@ERROR and ERROR_NUMBER()? |
|
3. | Can you commit a transaction in the catch block? |
|
Answers
1. | In the event of an error that might keep a transaction from completing successfully, you can tell SQL Server to roll back a transaction by setting the XACT_ABORT session option to ON. |
2. | The function @@ERROR returns the error number of the previously executed statement and can be used outside of a catch block. The function ERROR_NUMBER() returns the error number that belongs to the error that caused control to be transferred to the current catch block. If not inside of a catch block, ERROR_NUMBER() returns NULL. |
3. | Yes, you can commit a transaction in the catch block if the transaction is committable. Use the XACT_STATE() function to find out if it is. |