Insert Multiple rows using Transacrtions

  • Hi..

    I have a table and need insert multiple data into it. First i have delete all data into the table and then insert multiple rows in table using sql transactions so that if any error comes all data will not be deleted.

    Thanks and Regards

    Sankar

    Cochin

  • sankar.nandakumaran (6/28/2013)


    Hi..

    I have a table and need insert multiple data into it. First i have delete all data into the table and then insert multiple rows in table using sql transactions so that if any error comes all data will not be deleted.

    Thanks and Regards

    Sankar

    Cochin

    The quick answer for >SQL2008 would be something like:

    BEGIN TRAN

    [MERGE with INSERT. UPDATE, and DELETE]

    END TRAN

    Check out these articles:

    Using the MERGE Statement[/url]

    Merge error handling[/url]

     

  • For a single command (MERGE is a single command) you do not need "begin tran",

    each command starts implicit transaction, and commits/rollback implicitly, all the time (if not within larger transaction).

    Also, there is no "end tran" command, you probably meant "commit tran".

    _____________________________________________________
    Microsoft Certified Master: SQL Server 2008
    XDetails Addin - for SQL Developers
    blog.sqlxdetails.com - Transaction log myths
  • Vedran Kesegic (6/29/2013)


    Also, there is no "end tran" command, you probably meant "commit tran".

    You are correct about COMMIT TRAN. It was late after a long day! :blush:

     

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

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