transaction

  • In one of my stored procedure I am Inserting the data into 3 tables.

    BEGIN TRANSACTION trans1

    Insert into tbla(column1)

    VALUES(@variable1)

    Insert into tblb(columna)

    VALUES(@variable2)

    Insert into tbla(columnx)

    VALUES(@variable3)

     

    IF @@ERROR<>0

    BEGIN

    ROLLBACK TRANSACTION tran1

     

     

  • sorry guys this is an incomplete post.

  • this is how i typically do a big group of transactions;

    note that i use SET XACT_ABORT ON, which means if any error gets raised, it rollsback the transaction automatically, so i need never check for @@error:

    SET NOCOUNT ON

    SET XACT_ABORT ON

    BEGIN TRAN

    INSERT INTO TABLE1....

    UPDATE TABLE1...

    INSERT INTO TABLE2.....

    COMMIT TRAN

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 3 posts - 1 through 2 (of 2 total)

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