?
Solved

Looking for good sample of TSQL error-handling

Posted on 2008-10-15
4
Medium Priority
?
176 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
[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
  • 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 1000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
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…
Suggested Courses

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