Solved

Looking for good sample of TSQL error-handling

Posted on 2008-10-15
4
166 Views
Last Modified: 2010-04-21
Please point me to a page or provide me with a nice sample of error-handling with TSQL.
0
Comment
Question by:jdana
  • 2
  • 2
4 Comments
 
LVL 37

Expert Comment

by:momi_sabag
ID: 22719551
which sql server version?
0
 
LVL 37

Accepted Solution

by:
momi_sabag earned 250 total points
ID: 22719560
for v2005 and v2008 it's quite simple:

begin try
 do your code here...
end try
begin catch
 do your code here
end catch

inside the catch you can use error_number() and error_message() in order to understand which error happended

in sql 2000 you will have to use the @@error variable
0
 

Author Comment

by:jdana
ID: 22719641
Version 2005
0
 

Author Closing Comment

by:jdana
ID: 31506248
Thanks!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how the fundamental information of how to create a table.

708 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

11 Experts available now in Live!

Get 1:1 Help Now