CORRECT TEXT

Posted by: Pdfprep Category: 70-461 Tags: , ,

CORRECT TEXT

You plan to deploy a stored procedure for a database named TICKETS.

You need to implement error handling for the stored procedure to ensure that the system-defined error messages are returned if an error occurs upon insert. Part of the correct Transact-SQL has been provided in the answer are below. Enter the code in the answer area that resolves the problem and meets the stated goals or requirements.

You can add code within the code that has been provided as well as below it.

Use the ‘Check Syntax’ button to verify your work. Any syntax or spelling errors will be reported by line and character position.

Answer: Please review the explanation part for this answer

Explanation:

1 CREATE PROCEDURE AdCase

2 @CustomerId INT,

3 @ProblemId INT,

4 @Comment NVARCHAR (MAX)

5 AS

6

7 BEGIN TRY

8 INSERT INTO Cases

9 (CustomerId, ProblemId, Comment)

10 VALUES

11 (@CustomerId, @ProblemId, @Comment)

12 END TRY

13 BEGIN CATCH

14 INSERT INTO AppLog

15 (CurrentTime, ErrorNumber, CustomerId)

16 VALUES

17 (getdate(), ERROR_NUMBER(), @CustomerId);

18 THROW;

19

20 END CATCH

21

Make changes and additions in the above lines.

7 BEGIN TRY

12 END TRY

13 BEGIN CATCH

18 THROW;

20 END CATCH

References:

https://docs.microsoft.com/en-us/sql/t-sql/language-elements/try-catch-transact-sql?view=sqlserver-2017

https://docs.microsoft.com/en-us/sql/t-sql/language-elements/throw-transact-sql?view=sql-server-2017

Leave a Reply

Your email address will not be published.