GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Database  >  SQL Server
Go To First  |  Previous Question  |  Next Question 
 SQL Server  |  Question 90 of 99    Print  
How is the error handling in stored proc of T-SQL ?
1 How is the error handling in stored proc of T-SQL
2 What is clustered index and non-clustered index? How many clustered indexes and non-clustered indexes can be created in one table?
3-what is disconnected mode?



  
Total Answers and Comments: 5 Last Update: February 21, 2009     Asked by: ajay_shu007 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: seemu123
 

In SQL Server 2000
 We can check by @@Error<>0 i.e. error.
ex:
     IF @@Error<>0
          BEGIN

             ROLLBACK TRANSACTIOn

             RETURN

          END

     ELSE

          BEGIN

             COMMIT TRANSACTION

             RETURN

          END

Note: You need to check @@Error at every DML statement and since it is Global Variable, So it reset every time.

In SQL Server 2005
We can check by using try catch block
ex:

BEGIN TRY

BEGIN TRANSACTION
/*statement*/

COMMIT TRANSACTION

END TRY

BEGIN CATCH

IF @@TRANCOUNT>0

ROLLBACK TRAN

END CATCH

Note: You can check the following functions in catch block
a)ERROR_NUMBER() returns no of the error
b)ERROR_SEVERITY() returns severity of the error
c)ERROR_STATE() returns error state no
d)ERROR_PROCEDURE() returns name of stored procedure
e)ERROR_LINE() returns line no.
f)ERROR_Message() returns the complete text of the message



Above answer was rated as good by the following members:
neel_desai
June 21, 2008 04:56:22   #1  
sunilsoni30 Member Since: December 2007   Contribution: 4    

RE: How is the error handling in stored proc of T-SQL ?
error<> o
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
July 01, 2008 13:42:57   #2  
seemu123 Member Since: May 2008   Contribution: 15    

RE: How is the error handling in stored proc of T-SQL ?

In SQL Server 2000
We can check by @@Error<>0 i.e. error.
ex:
IF @@Error<>0
BEGIN

ROLLBACK TRANSACTIOn

RETURN

END

ELSE

BEGIN

COMMIT TRANSACTION

RETURN

END

Note: You need to check @@Error at every DML statement and since it is Global Variable So it reset every time.

In SQL Server 2005
We can check by using try catch block
ex:

BEGIN TRY

BEGIN TRANSACTION
/*statement*/

COMMIT TRANSACTION

END TRY

BEGIN CATCH

IF @@TRANCOUNT>0

ROLLBACK TRAN

END CATCH

Note: You can check the following functions in catch block
a)ERROR_NUMBER() returns no of the error
b)ERROR_SEVERITY() returns severity of the error
c)ERROR_STATE() returns error state no
d)ERROR_PROCEDURE() returns name of stored procedure
e)ERROR_LINE() returns line no.
f)ERROR_Message() returns the complete text of the message


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
July 17, 2008 13:12:16   #3  
suaveshiva Member Since: July 2008   Contribution: 1    

RE: How is the error handling in stored proc of T-SQL ?
Abt Clustered indexes:
V can hav only one clustered index in a table by default primary key is termed as clustered index.
V can have 249 non-clustered indexes in a table.

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
September 02, 2008 08:27:43   #4  
yemshivakumar Member Since: September 2008   Contribution: 1    

RE: How is the error handling in stored proc of T-SQL ?
We can use @@ERROR keyword for handling errors. RAISEERROR also we can use.
 
Is this answer useful? Yes | No
February 21, 2009 16:19:23   #5  
Tinkerbell Member Since: February 2009   Contribution: 1    

RE: Numebr of clustered and non clustered
You can have only one clustered index on a table and a maximum of 249 non clustered indexes.
 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape