Solved

sql server 2005

Posted on 2012-03-26
3
206 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
Comment Utility
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 76

Assisted Solution

by:arnold
arnold earned 250 total points
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
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…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now