Home » Microsoft » 70-457 » Which code segment should you add to line 14?
You use Microsoft SQL Server 2012 to create a stored procedure as shown in the following code segment. (Line numbers are included for reference only.)
The procedure can be called within other transactions. You need to ensure that when the DELETE statement from the HumanResourcesJobCandidate table succeeds, the modification is retained even if the insert into the Audit.Log table fails. Which code segment should you add to line 14?
A. IF @@TRANCOUNT = 0
B. IF (XACT_STATE ( ) ) = 0
C. IF (XACT_STATE ( ) ) = 1
D. IF @@TRANCOUNT = 1
Correct Answer: C
Explanation/Reference:
--Burgos - NO
IF (XACT_STATE()) = 1 -- Test whether the transaction is committable.
IF (XACT_STATE()) = -1 -- Test whether the transaction is uncommittable.
@@TRANCOUNT count number of transactions opened. In this case ALWAYS BE at least 1, because CATCH will be invoked only on error before COMMIT.
--Burgos
Verified answer as correct.
Reference: http://msdn.microsoft.com/en-us/library/ms189797.aspx
Reference: http://msdn.microsoft.com/en-us/library/ms187967.aspx