Solved

sql server 2005

Posted on 2012-03-26
3
212 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 78

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

688 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