nerdexam
Microsoft

70-465 · Question #97

You need to ensure that a stored procedure fails if an INSERT statment within the stored procedure fails. What action should you take?

The correct answer is C. SET XACT_ABORT ON. To ensure a stored procedure fails and rolls back its transaction if an INSERT statement within it fails, enable the XACT_ABORT option.

Submitted by mike_84· Mar 5, 2026Design and implement database solutions for SQL Server

Question

You need to ensure that a stored procedure fails if an INSERT statment within the stored procedure fails. What action should you take?

Options

  • ATHROW 51000, 'Abort!'
  • BSET XACT_ABORT OFF
  • CSET XACT_ABORT ON
  • DTRY....CATCH

How the community answered

(67 responses)
  • A
    3% (2)
  • B
    1% (1)
  • C
    94% (63)
  • D
    1% (1)

Why each option

To ensure a stored procedure fails and rolls back its transaction if an INSERT statement within it fails, enable the XACT_ABORT option.

ATHROW 51000, 'Abort!'

THROW raises an exception programmatically but does not automatically ensure transaction rollback for all types of run-time errors that an INSERT statement might encounter unless explicitly handled in a CATCH block.

BSET XACT_ABORT OFF

SET XACT_ABORT OFF means that if a T-SQL statement raises a run-time error, the transaction might not be rolled back entirely, and execution could continue, which is the opposite of the desired behavior.

CSET XACT_ABORT ONCorrect

SET XACT_ABORT ON ensures that if a T-SQL statement, such as an INSERT, within an explicit or implicit transaction encounters a run-time error, the entire transaction is automatically rolled back and the batch is terminated. This behavior guarantees that the stored procedure fails completely if the INSERT statement fails.

DTRY....CATCH

TRY...CATCH blocks are used for error handling and allowing recovery or custom error actions, but they do not inherently guarantee that an entire transaction will be rolled back upon an INSERT failure without explicit ROLLBACK TRANSACTION statements within the CATCH block.

Concept tested: SQL Server Transaction Abort Behavior (XACT_ABORT)

Source: https://learn.microsoft.com/en-us/sql/t-sql/statements/set-xact-abort-transact-sql

Topics

#T-SQL error handling#XACT_ABORT#Stored procedure robustness

Community Discussion

No community discussion yet for this question.

Full 70-465 Practice