Triggers inside Stored procedure

  • I have a proc whose structure is as below:

    Create Proc

    As

    Begin

    Insert Statement................... ( which calls insert trigger)

    ...

    ...( rest of the code )

    ...

    END

    If the Insert Statement Succeeds in inserting data but trigger produces an exception, then the rest of the code in the Proc will execute or not?

  • RAKSHITHA (10/21/2016)


    I have a proc whose structure is as below:

    Create Proc

    As

    Begin

    Insert Statement................... ( which calls insert trigger)

    ...

    ...( rest of the code )

    ...

    END

    If the Insert Statement Succeeds in inserting data but trigger produces an exception, then the rest of the code in the Proc will execute or not?

    If the trigger fails, the insert will roll back.

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • Does the exception in the trigger raise an error message? What is its severity number?

    John

  • My code is as below. I know that when the trigger raises an error the inserted row is reverted but after that, whether the execution of rest of the code continues or terminates the proc batch.

  • Your error has severity 16 - that will only abort the current statement, which means that your batch will continue to run after the error. Higher level errors (19 and above, I believe) will abort the batch, while errors that are higher still (I can't remember what the threshold is) will abort the connection.

    John

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply