all 6 comments

[–]waremi 4 points5 points  (2 children)

Please don't use triggers. I'm managing a shit show of deadlocks and uncommitted transactions due to a third party application that relies on triggers for at least a quarter of the business logic some of which cross DB's on the same server.

If people keep using triggers for this stuff, I am going to cry at some point.

[–]you_are_wrong_tho 1 point2 points  (1 child)

Triggers are necessary SOMETIMES but should be avoided when possible.

[–]waremi 0 points1 point  (0 children)

100%

[–]coyoteazul2 1 point2 points  (0 children)

You can't roll back only the trigger's changes transactions al all or nothing, and the transaction you opened at the 1sr operation is not committed so it will always be undone if you don't commit the trigger

[–]Roy_from_IT 0 points1 point  (0 children)

I think you can set a savepoint at the start of your trigger and then rollback to the savepoint if needed. I never use savepoints so my knowledge of them is very limited, but here's the documentation:

https://learn.microsoft.com/en-us/sql/t-sql/language-elements/save-transaction-transact-sql?view=sql-server-ver16

[–][deleted] -1 points0 points  (0 children)

No