PrepAway - Latest Free Exam Questions & Answers

Which code should you use?

You use SQL Server 2014 to maintain the data used by applications at your company.
You want to execute two statements.
You need to guarantee that either both statements succeed, or both statements fail together as a batch.
Which code should you use?

PrepAway - Latest Free Exam Questions & Answers

A.
Option A

B.
Option B

C.
Option C

D.
Option D
Option E

D.
Option D
Option E

Explanation:

Structure should be:
BEGIN TRY
BEGIN TRANSACTION
..
COMMIT TRANSACTION
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
END CATCH.

7 Comments on “Which code should you use?

      1. Dim says:

        C isn’t correct because @@error holds value for last statement.
        if the first insert will fail while the second succeeded the @@error
        value will be 0 and the transaction committed.




        0



        0

Leave a Reply