Home » Microsoft » 70-461 v.2 » Which six Transact-SQL statements should you use?
DRAG DROP
You use Microsoft SQL Server to develop a database application.
You create a stored procedure named usp_calculategrowth. The stored procedure modifies rows and can result in several different exceptions.
You need to ensure that when the stored procedure is executed, the following requirements are met:
• The calling application can receive a custom error message.
• The error is readable from the Windows Event Viewer of the server.
• The error isreadable in the SQL Error log.
Which six Transact-SQL statements should you use? (To answer, move the appropriate SQL statements from the list of statements to the answer area and arrange them in the correct order.)
Select and Place:
Correct Answer:
Explanation/Reference:
Box 1: BEGIN TRY
A TRY…CATCH construct consists of two parts: a TRY block and a CATCH block. When an error condition is detected in a Transact-SQL statement that is inside
a TRY
block, control is passed to a CATCH block where the error can be processed.
A TRY blockstarts with the BEGIN TRY statement and ends with the END TRY statement.
Box 2: Exec usp.calculategrowth
Box 3: END TRY
Box 4: BEGIN CATCH
A TRY block must be followed immediately by a CATCH block. A CATCH block starts with the BEGIN CATCH statement andends with the END CATCH statement.
Box 5: EXEC
xp_logevent… xp_logevent logs a user-defined message in the SQL Server log file and in the Windows Event Viewer, xp_logevent can be used to send an alert without sending
a
message to the client.
Incorrect:
Not RAISERROR: RAISERROR generates an error message and initiates error processing for the session.
The message is returned as a server error message to the calling application or to an associated CATCH block of a TRY…CATCH construct. New applicationsshould use THROW instead.
Box 6: END CATCH
References:
https://msdn.microsoft.com/en-us/library/msl86244.aspx
https://technet.microsoft.com/en-us/library/ms179296(v=sql.l 05).aspx