Click here to Skip to main content
15,906,558 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Experts
I Have Stored Procedure and apply transaction on that S.P in between of S.P There is Trigger fire in S.P and Trigger also have transaction apply and if there is any exception or error occure in Trigger then S.P "roll back" or "Commit" the transaction.

E.g

SQL
Create S.P abc
as
Begin Transaction
Try
select * From xyz
Update rst set a='1' where r='z' --when update trigger fire on rst table update trigger
select * from rst
Commit
catch
Rollback
end
End Transaction

Create Trigger nc on rst
update
Begin Transaction
Try
-----------any thing logic here-
Commit
catch
Rollback 
end
end Transaction


-- But in My Trigger Exception Occurs then next statement in S.P is Run or Whole S.P Rollback
--Or Another Case Suppose My Trigger Run Successfully without error and error occur in S.P then But Happen.
Posted
Updated 28-Sep-11 0:55am
v3
Comments
CodingLover 28-Sep-11 6:28am    
Can you please elaborate your question. It's not clear enough to me.
André Kraak 28-Sep-11 6:31am    
Your question is not clear, try rephrasing it and/or be more specific.
Do you mean that failure in the trigger should result in a roll back of the transactions performed in the stored procedure?

If you wish to change your question use the Improve Question button.

1 solution

You are abusing the trigger and stored procedures.

It is better to put the trigger functionality with in your stored procedure so you can control what is happening.
 
Share this answer
 
Comments
Er. Dinesh Sharma 28-Sep-11 7:01am    
Its OK i understand but i put dummy code in above example.suppose we have such type of requirement then what happen at that case.
Mehdi Gholam 28-Sep-11 7:04am    
Write what you have in your trigger inside the stored procedure.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900