SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Insert Multiple rows using Transacrtions


Insert Multiple rows using Transacrtions

Author
Message
sankar.nandakumaran
sankar.nandakumaran
SSC Rookie
SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)

Group: General Forum Members
Points: 35 Visits: 39
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
Steven Willis
Steven Willis
SSC Eights!
SSC Eights! (871 reputation)SSC Eights! (871 reputation)SSC Eights! (871 reputation)SSC Eights! (871 reputation)SSC Eights! (871 reputation)SSC Eights! (871 reputation)SSC Eights! (871 reputation)SSC Eights! (871 reputation)

Group: General Forum Members
Points: 871 Visits: 1721
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

Merge error handling

 
Vedran Kesegic
Vedran Kesegic
Right there with Babe
Right there with Babe (762 reputation)Right there with Babe (762 reputation)Right there with Babe (762 reputation)Right there with Babe (762 reputation)Right there with Babe (762 reputation)Right there with Babe (762 reputation)Right there with Babe (762 reputation)Right there with Babe (762 reputation)

Group: General Forum Members
Points: 762 Visits: 1266
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

Steven Willis
Steven Willis
SSC Eights!
SSC Eights! (871 reputation)SSC Eights! (871 reputation)SSC Eights! (871 reputation)SSC Eights! (871 reputation)SSC Eights! (871 reputation)SSC Eights! (871 reputation)SSC Eights! (871 reputation)SSC Eights! (871 reputation)

Group: General Forum Members
Points: 871 Visits: 1721
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

 
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search