Aan de slagGa gratis aan de slag

The TRY...CATCH syntax

You want to insert a new product in your products table. You prepare this script, trying to control the execution if an error occurs. You use the TRY...CATCH construct you learned to handle the possible errors.

BEGIN TRY
    INSERT INTO products (product_name, stock, price)
        VALUES ('Trek Powerfly 5 - 2018', 10, 3499.99);
    SELECT 'Product inserted correctly!';

    BEGIN CATCH
        SELECT 'An error occurred! You are in the CATCH block';   
    END CATCH
END TRY

Which of the following is true about the syntax?

Deze oefening maakt deel uit van de cursus

Transactions and Error Handling in SQL Server

Cursus bekijken

Praktische interactieve oefening

Zet theorie om in actie met een van onze interactieve oefeningen.

Begin met trainen