HOTSPOT
You are creating a database solution to track sales achievements of your training courses. You run the following statements:
You plan to add courses to a table named HighlightedCourses. You must add courses that have been delivered to more than 100 participants only.
If the total number of participants for a course is lower than 100, the course must not be added to the HighlightedCourses table. In addition, an error message must be displayed and remaining Transact-SQL code must not run.
How should you complete the Transact-SQL statement? To answer, select the appropriate Transact-SQL segments in the answer area.
NOTE: Each correct selection is worth one point.
Answer:
Explanation:
Box 1: IF (@TotalParticipants < 100)
Box 2: THROW TRHOW raises an exception and transfers execution to a CATCH block of a TRY…CATCH construct. If a TRY…CATCH construct is not available, the statement batch is terminated. The line number and procedure where the exception is raised are set.
Incorrect Answers: Not BREAK: BREAK exits the current WHILE loop. If the current WHILE loop is nested inside another, BREAK exits only the current loop, and control is given to the next statement in the outer loop.
Not RAISERROR: Microsoft recommends that THROW should be used instead of RAISERROR.
References: https://docs.microsoft.com/en-us/sql/t-sql/language-elements/throw-transact-sql