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?
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.
Only D is correct. If no transaction, one of them will still succeed.
I agree it is D only
D is correct
What about “C”? Is “C” really incorrect?!
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.
Yes, I sure D
My answer is D as well
http://msdn.microsoft.com/en-us/library/ms175976.aspx