Is there a way to update a record in an audit table (via triggers) without that record being locked due to the update which fired the trigger was inside a transaction.
So we have a Users table and a trigger that fires on insert, update, delete and logs the changed values to some Audit table, however i do not want the audit table to be locked preventing other triggers from firing which do actions on the audit table.
edit: just to clarify, the issue I have is that multiple tables report to the same audit table via different triggers, so an update to one table locks all the other tables from being updated. As for the concerns about what if transactions roll back, this is not such a concern as the audit table is there just for change tracking and if the record rolls back it is not an issue if the audit table does not roll back.
I have thought of a way it might work but I do not know if this is possible (or how to do it), is there a way have a trigger use a new connection instead of the one that was initially called?
It is impossible to create an action that does not at least place a write lock on the record/page being written. SQL Server would otherwise have consistency issues all the time. You should be looking from the opposite angle – the other processes that need to access the audit table (audit normally means read only with little to no update) should use
Which will dirty-read (or versioned without locking) from the audit table
If you must..
There is a sneaky way to isolate the write from the transaction using Service Broker by instead inserting data to an intermediate table and having the SSSB asychronous activation thread write the audit record for you, allowing your original long running transaction to remain uncommitted.