locked
transactions with try catch block RRS feed

  • Question

  • Hi,

    I am using sql server 2008. And there is a very critical procedure in my application in which lot of transactions takes place. I need to control the transactions in this procedure. Below is how I have controlled my transaction along with try catch block. Please let me know if this is the best way or is there any other way which you think is better.

    BEGIN TRY
    BEGIN TRANSACTION
    
    	insert statements
    
    	update statements
    
    	delete statements
    
    	COMMIT TRANSACTION;
    
    	SELECT 'record inserted successfully'
    	RETURN
    
    END TRY
    BEGIN CATCH 
    	IF @@trancount > 0 
    	ROLLBACK TRANSACTION;
    	
    	SELECT 'some error while updating the records'
    	RETURN
    
    	
    
    END CATCH


    Please mark as helpful and propose as answer if you find this as correct!!! Thanks, Rakesh.

    Thursday, January 24, 2013 11:14 AM

Answers

All replies