exam questions

Exam 70-761 All Questions

View all questions & answers for the 70-761 exam

Exam 70-761 topic 1 question 16 discussion

Actual exam question from Microsoft's 70-761
Question #: 16
Topic #: 1
[All 70-761 Questions]

HOTSPOT -
You need to develop a Transact-SQL statement that meets the following requirements:
✑ The statement must return a custom error when there are problems updating a table.
✑ The error number must be value50555.
✑ Theerror severity level must be14.
✑ A Microsoft SQL Server alert must be triggered when the error condition occurs.
Which Transact-SQL segment should you use for each requirement? To answer, select the appropriate Transact-SQL segments in the answer area.
Hot Area:

Show Suggested Answer Hide Answer
Suggested Answer:
Box 1: TRY"¦CATCH -
The TRY...CATCH Transact-SQL construct implements error handling for Transact-SQL that is similar to the exception handling in the Microsoft Visual C# and
Microsoft Visual C++ languages. A group of Transact-SQL statements can be enclosed in a TRY block. If an error occurs in the TRY block, control is passed to another group of statements that is enclosed in a CATCH block.
Box 2: RAISERROR(50555, 14, 1 'The update failed.") WITH LOG
We must use RAISERROR to be able to specify the required severity level of 14, and we should also use the LOG option, which Logs the error in the error log and the application log for the instance of the Microsoft SQL Server Database Engine, as this enable a MS MS SQL SERVER alert to be triggered.
Note: 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.
Incorrect Answers:
Not THROW: THROW does not have a severity parameter.
References:
https://msdn.microsoft.com/en-us/library/ms175976.aspx
https://msdn.microsoft.com/en-us/library/ms178592.aspx

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
chaoxes
Highly Voted 4 years, 9 months ago
Correct answers are: TRY...CATCH Raiseerror ... WITH LOG Passed exam today with 970 score and had it on my exam.
upvoted 11 times
...
Vermonster
Most Recent 4 years, 4 months ago
TRY..CATCH, RAISERROR WITH LOG - 100%
upvoted 1 times
...
SimSql
4 years, 4 months ago
The answer is WITH NOWAIT. To raise error with severity 19 and above you have to add the option WITH LOG, which logs the error in the SQL Server error log as well as the Windows application log. To use the WITH LOG option you must be a member of the sysadmin role or have the ALTER TRACE permission. SQL Server Agent fires an alert when a specific error occurs. For example, you might specify error number 2571 to respond to unauthorized attempts to invoke Database Console Commands (DBCC). SQL Server Agent fires an alert when any error of the specific severity occurs. For example, you might specify a severity level of 15 to respond to syntax errors in Transact-SQL statements.
upvoted 1 times
...
Hoglet
4 years, 5 months ago
The 2 important requirements are that it be Severity 14 and a SQL Server Alert be triggered. For any severity other than 16, you have to use RAISERROR. A SQL Server Alert is an object setup under the SQL Server Agent. You can specify the Alert by error number or severity. The alert with trigger when an error is raised WITH LOG. So the option has to be RAISERROR....WITH LOG A SQL Server Alert is nothing to do with the client.
upvoted 2 times
...
Oooo
4 years, 8 months ago
Continuing..So first you need to make an entry in sys.messages using a stored procedure sp_addmessage (you cannot just insert a value in system objects) "exec sp_addmessage 50555,14,N'the update failed'" 4. And now use RAISERROR so the answer is either 2 or 3 (most probably 3 because NOWAIT send the log message instantly to the user or the client) Happy learning :)
upvoted 1 times
Hoglet
4 years, 5 months ago
A SQL Server Alert is the Alert you will find under the SQL Server Agent. Once you have setup an Alert, it will trigger when a matching error is raised WITH LOG. Alerts are nothing to do tith the user / client
upvoted 2 times
...
...
Oooo
4 years, 8 months ago
Okay there are couple of things this question sheds some light on - 1. The answer cannot be THROW because when you use THROW to throw an user defined error, the severity is always set to 16. 2.When THROW is used to throw and user defined function, the message_id doesn't need to be stored in sys.messages table.(Here the message id is 50555) 3.However when you use RAISERROR to throw an UD error message then it is mandatory to have a message_ID associated with the user defined test message in sys.messages. If you just raiserror with that message_id it will raise an error but the error message wouldn't have the user defined message becasue it doesnt have that particular message_id in sys.messages table. This is the error message that is thrown: "Error 50555, severity 14, state 1 was raised, but no message with that error number was found in sys.messages. If error is larger than 50000, make sure the user-defined message is added using sp_addmessage." Continued in next comment
upvoted 1 times
...
Oooo
4 years, 8 months ago
The correct answer is Raiserror with nowait
upvoted 1 times
...
gtc108
5 years, 3 months ago
xp_logevent can be used to log 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. Correct answer is WITH LOG: https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/xp-logevent-transact-sql?view=sql-server-ver15
upvoted 2 times
...
Robintang0924
5 years, 4 months ago
It has to be raiserror to meet requirement of 'severity level must be 14.' since by default throw always return 16. Plus we need nowait option to return error to client immediately.
upvoted 1 times
flashed
5 years, 2 months ago
No, the condition severity 16 is only for THROW, not for RAISEERROR
upvoted 1 times
...
...
Bartek
5 years, 8 months ago
"A Microsoft SQL Server alert must be triggered when the error condition occurs." Seems to be correct answer "..With Nowait" Ref. Itzik Ben-Gan QUerying Microsoft Sql Server 2014" "You can issue RAISERROR with a severity level > 20 if you use the WITH LOG option and if you have the SQL Server sysadmin role. SQL Server will then terminate the connection when the error is raised. -You can use RAISERROR with NOWAIT to send messages immediately to the client. The message does not wait in the output buffer before being sent."
upvoted 1 times
M4x
5 years, 8 months ago
With NO WAIT you send immediately the error to the CLIENT (ASP.NET, Console, ecc) with LOG you send the error to the SQL Server logging. https://docs.microsoft.com/en-us/sql/t-sql/language-elements/raiserror-transact-sql?view=sql-server-2017
upvoted 6 times
tcroots19
5 years, 2 months ago
so, what are you saying, it mentioned "when the error condition occurs", which seems like the NO WAIT WITH LOG seems like it would buffer...then send, right?
upvoted 1 times
...
...
Hoglet
4 years, 5 months ago
You can use WITH LOG at any severity, but require the correct permissions, You have to use WITH LOG for severity 19 or higher. Severity 20 or higher will kill the connection
upvoted 1 times
...
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago