Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
gemispence
Yak Posting Veteran
71 Posts |
Posted - 2006-02-16 : 18:10:49
|
I'm performing a stored proc that has 4 inserts. I only want the inserts to complete as a batch. If one fails, I want to rollback the whole transaction. Does anyone know the syntax?? :) |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-02-16 : 18:46:00
|
[code]INSERT 1IF @@ERROR <> 0BEGIN ROLLBACK TRAN RETURNENDINSERT 2IF @@ERROR <> 0BEGIN ROLLBACK TRAN RETURNENDINSERT 3IF @@ERROR <> 0BEGIN ROLLBACK TRAN RETURNENDINSERT 4IF @@ERROR <> 0 ROLLBACK TRANELSE COMMIT TRANRETURN[/code]You can use GOTO with labels to avoid the repetitive code. Check out GOTO in SQL Server Books Online for more details.Tara Kizeraka tduggan |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
Kristen
Test
22859 Posts |
Posted - 2006-02-17 : 01:26:36
|
Tara: Do you need a BEGIN TRANSACTION before INSERT 1 (or is it implicit perhaps)?Kristen |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-02-17 : 12:39:41
|
Of course! BEGIN TRANINSERT 1...Tara Kizeraka tduggan |
|
|
|
|
|