70-464 Exam QuestionsBrowse all questions from this exam

70-464 Exam - Question 41


You use SQL Server to maintain the data used by applications at your company.

You need to run two separate SQL statements.

You must guarantee that the following three things happen:

Either BOTH statements succeed or BOTH statements fail as a batch.

Exam 70-464 Question 41

✑ If an error occurs on the first statement, SQL should not attempt to run the second statement.

✑ Error information should be returned to the client.

What should you do?

Exam 70-464 Question 41
Show Answer
Correct Answer: A

To ensure that both statements either succeed or fail as a batch and that error information is returned to the client, you should use a TRY...CATCH block with SET XACT_ABORT ON. SET XACT_ABORT ON ensures that if a runtime error occurs, the entire transaction is rolled back. The TRY...CATCH block captures errors and returns them to the client. Therefore, option A is the correct approach.

Discussion

2 comments
Sign in to comment
Williamzhou
Nov 25, 2020

I think correct answer is C. Answer A doesn't have error returned to client.

LiamLin
Aug 29, 2021

Should be answer D. Answer C doesn't have commit transaction