TRY..CATCH block not catching failed insert statements RRS feed

  • Question

  • Hello,

    I have a SQL script that is inserting several items into a table; however, on the last, the table name is incorrect, which causes an error. The problem I am having is, the TRY..CATCH is not catching this incorrect table name, thus not rolling back the overall transaction, so I have items that are inserted which are not rolled back.

    Am I doing something wrong with my TRY..CATCH and TRANSACTION?


    begin try
    	-- Set the name of the transaction
    	declare @Transaction varchar(20);
    	set @Transaction = 'TestTransaction';
    	begin transaction @Transaction;
    		insert into
    		insert into 
    		values ('a')
    end try
    begin catch
    	rollback transaction @Transaction;
    end catch


    Wednesday, June 2, 2010 5:59 PM


All replies