Solved

sql server 2005

Posted on 2012-03-26
3
207 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how the fundamental information of how to create a table.

896 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

13 Experts available now in Live!

Get 1:1 Help Now