Solved

sql server 2005

Posted on 2012-03-26
3
208 Views
Last Modified: 2012-08-14
How do I put a stop on my procedure on error? There're many parts of my procedure, and want it to stop on any part that it occur an error, i.e, when it can't append the records to the table because of key violation, I want the procedure to stop there and not executing the next part. Please help me with the syntax.
0
Comment
Question by:HNA071252
3 Comments
 
LVL 9

Expert Comment

by:OCDan
ID: 37768111
In short there isn't really a quick way to do this, but THIS LINK explains different ways to do error catching very well and why one method is better than another.
0
 
LVL 77

Assisted Solution

by:arnold
arnold earned 250 total points
ID: 37768361
In a way it all depends on the meaning of "error."

Are you looking at an insert/update and get an error response that the update you are trying to run is invalid or the user executing the stored procedure does not have the rights to the underlying table.
http://www.novicksoftware.com/tipsandtricks/tips-erorr-handling-in-a-stored-procedure.htm

there are @error and system events that you can check and rollback the transaction.
Or have conditions on continuing in the stored procedure as long as no prior errors were seen.
0
 
LVL 25

Accepted Solution

by:
TempDBA earned 250 total points
ID: 37768703
When you define your stored procedure, set xact_abort property to on. This will ensure the rollback of the transaction and stops the execution of the procedure. Check out the following link:-

http://msdn.microsoft.com/en-us/library/ms188792.aspx
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
I have a large data set and a SSIS package. How can I load this file in multi threading?
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

806 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question