You need to create a stored procedure that meets the fo…

DRAG DROP
You need to create a stored procedure that meets the following requirements:
Produces a warning if the credit limit parameter is greater than 7,000
Propagates all unexpected errors to the calling process
How should you complete the Transact-SQL statement? To answer, drag the appropriate Transact-SQP
segments to the correct locations. Each Transact-SQL segments may be used once, more than once, or not at
all. You may need to drag the split bar between panes or scroll to view content.
Select and Place:

DRAG DROP
You need to create a stored procedure that meets the following requirements:
Produces a warning if the credit limit parameter is greater than 7,000
Propagates all unexpected errors to the calling process
How should you complete the Transact-SQL statement? To answer, drag the appropriate Transact-SQP
segments to the correct locations. Each Transact-SQL segments may be used once, more than once, or not at
all. You may need to drag the split bar between panes or scroll to view content.
Select and Place:

Answer:

Explanation:
Box 1: THROW 51000, ‘Warning: Credit limit isover 7,000!”,1
THROW raises an exception and transfers execution to a CATCH block of a TRY…CATCH construct in SQL
Server.
THROW syntax:
THROW [ { error_number | @local_variable },
{ message | @local_variable },
{ state | @local_variable } ]
[ ; ]
Box2: RAISERROR (@ErrorMessage, 16,1)
RAISERROR generates an error message and initiates error processing for the session. RAISERROR can
either reference a user-defined message stored in the sys.messages catalog view or build a message
dynamically. 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 applications should use THROW instead.
Severity levels from 0 through 18 can be specified by any user. Severity levels from 19through 25 can only be
specified by members of the sysadmin fixed server role or users with ALTER TRACE permissions. For severity
levels from 19 through 25, the WITH LOG option is required.
On Severity level 16. Using THROW to raise an exception
The following example shows how to use the THROW statement to raise an exception.
Transact-SQL
THROW 51000, ‘The record does not exist.’, 1;
Here is the result set.
Msg 51000, Level 16, State 1, Line 1
The record does not exist.
Note: RAISERROR syntax:
RAISERROR( { msg_id | msg_str | @local_variable }{ ,severity ,state }
[ ,argument [ ,…n ] ] )
[ WITH option [ ,…n ] ]
Note: The ERROR_MESSAGE function returns the message text of the error that caused the CATCH block of
a TRY…CATCH construct to be run.

https://msdn.microsoft.com/en-us/library/ms178592.aspx
https://msdn.microsoft.com/en-us/library/ms190358.aspx
https://msdn.microsoft.com/en-us/library/ee677615.aspx



Leave a Reply 1

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