Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

sql server transactions not committing within an instead of insert trigger

Avatar of adimit
adimit asked on
Microsoft SQL ServerMicrosoft SQL Server 2005SQL
4 Comments1 Solution732 ViewsLast Modified:
I have some code in an instead of trigger(on a table) that performs the following
begin try
declare@ .........
 set @erred = 0  
 begin transaction @t1
set @erred = 0
insert into table x from inserted ......

commit transaction@t1
set @erred =0
end try
begin catch
        if @erred = 1 begin	rollback transaction @t1 END
	DECLARE @TIME AS DATETIME
	SET @TIME = GETDATE()
	EXEC USP_GETERRORINFO @TIME

end catch

This transaction is placed on tables 1,2,3,4 and 5
I execute the transaction on table 1  by inserting valid data into table 1.  The trigger successfully sends data into table x.

I execute the transaction on table 2 by inserting invalid data into table 2, thus forcing an error. the trigger doesn't add any new data, but the data inserted by the successful transaction in table 1also gets deleted.

Why is that? I.e why does the 'old' data get deleted as well.Does the transaction stay open for some reason all the time. The text for @t1 is different in each trigger. I can guarantee that there are no delete statements in the code
ASKER CERTIFIED SOLUTION
Avatar of radcaesar
radcaesarFlag of India image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answers