PrepAway - Latest Free Exam Questions & Answers

Which five Transact-SQL segments should you use to deve…

DRAG DROP
You have two tables named UserLogin and Employee respectively.
You need to create a Transact-SQL script that meets the following requirements:
The script must update the value of the IsDeleted column for the UserLogin table to1if the value of the Id
column for the UserLogin table is equal to1.
The script must update the value of the IsDeleted column of the Employee table to1if the value ofthe Id
column is equal to1for the Employee table when an update to the UserLogin table throws an error.
The error message “No tables updated!” must be produced when an update to the Employee table throws
an error.
Which five Transact-SQL segments should you use to develop the solution? To answer, move the appropriate
Transact-SQL segments from the list of Transact-SQL segments to the answer area and arrange them in the
correct order.
Select and Place:

PrepAway - Latest Free Exam Questions & Answers

Answer:

Explanation:
A TRY block must be immediately followed by an associated CATCH block. Including any other statements
between the END TRY and BEGIN CATCH statements generates a syntax error.
https://msdn.microsoft.com/en-us/library/ms175976.aspx

7 Comments on “Which five Transact-SQL segments should you use to deve…

  1. Peter says:

    Correct answer is:

    BEGIN TRY
    UPDATE dbo.UserLogin
    SET IsDeleted = 1
    WHERE Id = 1
    END TRY

    BEGIN CATCH

    BEGIN TRY
    UPDATE dbo.Employee
    SET IsDeletedFlag = 1
    WHERE Id = 1
    END TRY

    BEGIN CATCH
    RAISERROR (‘No tables updated!’,16,1)
    END CATCH

    END CATCH




    37



    2
  2. eder says:

    ————————
    BEGIN TRY
    UPDATE dbo.UserLogin
    SET isDeleted=1
    WHERE ID=1
    END TRY/*human error*/
    ———————
    BEGIN CATCH
    ————————
    END CATCH
    ————————-
    BEGIN TRY
    UPDATE dbo.Employee
    SET isDeleted=1
    WHERE ID=’eder’
    END TRY
    ——————————–
    BEGIN CATCH
    THROW 51000,’NO TABLES UPDATED’,1
    END CATCH
    ——————————-




    0



    9
  3. eder says:

    TRY…CATCH constructs can be nested. Either a TRY block or a CATCH block can contain nested TRY…CATCH constructs. For example, a CATCH block can contain an embedded TRY…CATCH construct to handle errors encountered by the CATCH code.

    ———————————————-
    —https://docs.microsoft.com/en-us/sql/t-sql/language-elements/try-catch-transact-sql?view=sql-server-2017
    —————————
    TRY … las construcciones CATCH pueden ser anidadas. Un bloque TRY o un bloque CATCH pueden
    contener construcciones TRY … CATCH anidadas.
    Por ejemplo, un bloque CATCH puede contener una construcción TRY … CATCH incrustada para manejar
    los errores encontrados por el código CATCH.

    CREATE SCHEMA DataOwner
    GO

    create TABLE DataOwner.UserLogin
    (ID INT ,
    IsDeleted INT constraint ISdeletedCheck CHECK (IsDeleted=0 )
    )

    CREATE TABLE DataOwner.Employee
    (ID INT ,
    IsDeleted INT constraint IsDeletedChk CHECK (IsDeleted=0 or IsDeleted=1)
    )

    INSERT INTO DataOwner.UserLogin VALUES (1,0),(2,0)
    INSERT INTO DataOwner.Employee VALUES (1,0),(2,0)

    ————————
    BEGIN TRY
    UPDATE DataOwner.UserLogin
    SET isDeleted=1
    WHERE ID=1
    END TRY/*human error*/
    ———————
    BEGIN CATCH
    ————————
    BEGIN TRY
    UPDATE DataOwner.Employee
    SET isDeleted=1
    WHERE ID=1
    END TRY
    ——————————–
    BEGIN CATCH
    RAISERROR(‘No tables updated’,16,1)
    END CATCH
    ——————————-
    END CATCH
    ————————————————




    1



    0

Leave a Reply