What should you include in your design?

DRAG DROP
You are planning to deploy a database to Windows Azure SQL Database.
You need to design a stored procedure to update rows. The stored procedure must meet the following
requirements:
If the update fails, an error must be raised to the application and the update must be discarded.
The stored procedure must be designed to maximize concurrency.
What should you include in your design?
To answer, move the appropriate actions from the list of actions to the answer area and arrange them in the
correct order.
Select and Place:

DRAG DROP
You are planning to deploy a database to Windows Azure SQL Database.
You need to design a stored procedure to update rows. The stored procedure must meet the following
requirements:
If the update fails, an error must be raised to the application and the update must be discarded.
The stored procedure must be designed to maximize concurrency.
What should you include in your design?
To answer, move the appropriate actions from the list of actions to the answer area and arrange them in the
correct order.
Select and Place:

Answer:

Explanation:
Note:
* Read Committed is SQL Server’s default isolation level.
* @@ROWCOUNT
eturns the number of rows affected by the last statement.
* Using TRY…CATCH in a transaction
The following example shows how a TRY…CATCH block works inside a transaction. The statement inside the
TRY block generates a constraint violation error.
BEGIN TRANSACTION;
BEGIN TRY
— Generate a constraint violation error.
DELETE FROM Production.Product
WHERE ProductID = 980;
END TRY
BEGIN CATCH
SELECT
ERROR_NUMBER() AS ErrorNumber
,ERROR_SEVERITY() AS ErrorSeverity
,ERROR_STATE() AS ErrorState
,ERROR_PROCEDURE() AS ErrorProcedure
,ERROR_LINE() AS ErrorLine
,ERROR_MESSAGE() AS ErrorMessage;
IF @@TRANCOUNT > 0
ROLLBACK TRANSACTION;
END CATCH;
IF @@TRANCOUNT > 0
COMMIT TRANSACTION;
GO
http://msdn.microsoft.com/en-us/library/ms175976.aspx



Leave a Reply 1

Your email address will not be published. Required fields are marked *


Razor

Razor

1. Begin an explicit transaction
2. Perform the update in a try block

Alternative 1:
3. BEGIN CATCH (There is no CATCH Block without raising an error)
4. Read the @@ROWCOUNT system variable
5. Raise an Error and roll back the transaction if the rowcount is less than 1

Alternative 2:
3. Raise an error in a catch block
4. Rollback Transaction (There is no rollback block without rowcount etc.)

(There is no finally block in SQL Server. Usually you would work with XACT_ABORT = ON for this requirement)