|
-
Jan 24th, 2008, 10:15 PM
#1
Thread Starter
Addicted Member
Stored Procedure Execution of Multiple Scripts
Hi, I'm not sure what terms to search so I decided to post it as a new thread.
I have a stored procedure with multiple 'update' scripts to multiple tables. Sometimes I do get unexpected errors with one or more of the scripts, but when this scenario happens, all the other scripts run smoothly. How can I prevent this from happening? I want all the scripts execute sequentially and if there is an error in one or more of the scripts then the stored procedure shouldn't run at all.
Thank in advance.
C++ Programming is overwhelming.
Dont let it overwhelm you or you'll fall into the oblivion of its perfection
-
Jan 24th, 2008, 11:19 PM
#2
Re: Stored Procedure Execution of Multiple Scripts
What kind of scrips are you talking about ?
Why don't you start a transaction at the beginning of the procedure, and roll back if you get any kind of error ?
-
Jan 25th, 2008, 06:46 AM
#3
Re: Stored Procedure Execution of Multiple Scripts
You need to do aggresive tracking of @@ERROR and handle that with ROLLBACK or COMMIT at the end of the SPROC's.
Please show us a bit of your SPROC code so we can assist you with how that would be done.
-
Jan 25th, 2008, 09:12 AM
#4
Re: Stored Procedure Execution of Multiple Scripts
If you don't want to check the @@ERROR every single time you do an insert/update, then you can do it more easier like this:
sql Code:
SET XACT_ABORT ON
BEGIN TRANSACTION
INSERT INTO a (b,c) VALUES('aa', 'bb')
INSERT INTO a (b,c) VALUES('aa', 'bb')
INSERT INTO a (b,c) VALUES('cc', 'hh')
COMMIT TRANSACTION
It explains about it here: SET XACT_ABORT (Transact-SQL)
It will couse to roll back the entire transaction, when there is any kind of error...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|