How to Handle the exceptions in Sqlsrver 2005??
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
What is identity?
What is the difference between left and right outer join?
1.can we set the more than 1 primary keys for a table? 2.please give me the difference between Cluster Index and non-Clustered Index 3.can we use query like this "Select * from Table1,Table2;"
What is storeprocedure?Tell me synatx for how to write stored procedure.
How to provide default values to stored procedure parameters?
Is it true, that there is no difference between a rule and a check constraint?
How to remove duplicate rows from table except one?
Do you know the policy based administration feature of sql server 2008?
Are resultset updatable?
What is a cursor in SQL Server 2000 and their types?
Why is DML provided?
1 Answers Ernst Young, Thomson Reuters,
what is difference between Enterprise Manager and Query Analyer