How to Handle the exceptions in Sqlsrver 2005??

Answers were Sorted based on User's Feedback



How to Handle the exceptions in Sqlsrver 2005??..

Answer / manikanta.srinu

Sqlsrver 2005 introduced try-catch block in SQL. orelse you
can use Transation to Handle error in SQL

Is This Answer Correct ?    5 Yes 0 No

How to Handle the exceptions in Sqlsrver 2005??..

Answer / neetu

In SQLSERVER 2005 exceptions are handle by using RaisError
with Try catch like in other prog languages.
Begin Try

End try

Begin Catch

End Catch
BEGIN TRY

RAISERROR ('Yaa, I ma the problem', 16,1)

END TRY



BEGIN CATCH

SELECT ERROR_NUMBER() as ERROR_NUMBER,

ERROR_SEVERITY() as ERROR_SEVERITY,

ERROR_STATE() as ERROR_STATE,

ERROR_MESSAGE() as ERROR_MESSAGE

END CATCH



ERROR_NUMBER() returns the number of the error.
ERROR_SEVERITY() returns the severity.
ERROR_STATE() returns the error state number.
ERROR_PROCEDURE() returns the name of the stored procedure
or trigger where the error occurred.
ERROR_LINE() returns the line number inside the routine that
caused the error.
ERROR_MESSAGE() returns the complete text of the error
message. The text includes the values supplied for any
substitutable parameters, such as lengths, object names or
times.

Is This Answer Correct ?    3 Yes 0 No

How to Handle the exceptions in Sqlsrver 2005??..

Answer / indraneelandhavarapu

With SQL Server 2005, new error handling has been introduced
with the TRY...CATCH processing. Basically what happens is
when an error occurs the processing in the TRY block stops
and processing is then picked up in the CATCH block.

ERROR_NUMBER() Returns the number of the error
ERROR_SEVERITY() Returns the severity
ERROR_STATE() Returns the error state number
ERROR_PROCEDURE() Returns the name of the stored procedure
or trigger where the error occurred
ERROR_LINE() Returns the line number inside the routine
that caused the error
ERROR_MESSAGE() Returns the complete text of the error
message. The text includes the values supplied for any
substitutable parameters, such as lengths, object names, or
times

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More SQL Server Interview Questions

How to drop existing indexes in ms sql server?

0 Answers  


What languages bi uses to achieve the goal?

0 Answers  


write down the code for "how we delete a table without using of Drop command " ?

7 Answers   CarrizalSoft Technologies, Sonata,


How to list all field names in the result set using mssql_field_name()?

0 Answers  


What is a trace frag?

0 Answers  






What are mdf,ndf,ldf files and how to see the data in those files?

6 Answers   Accenture,


How does using a separate hard drive for several database objects improves performance right away?

0 Answers  


Will sql server 2005 allow you to reduce the size of a column?

0 Answers  


What are dml triggers and types of dml triggers?

0 Answers  


What is data source view or dsv? : sql server analysis services, ssas

0 Answers  


can a database be shrunk to 0 bytes, if not, why? : Sql server administration

0 Answers  


How many types of subqueries are there in sql server?

0 Answers  


Categories