Debugging SQL Server Triggers
Rule 1
The hardest way to debug SQL Server triggers is to log the DELETED and INSERTED virtual tables into log files.
The easiest way to debug SQL Server triggers is to create audit tables, and record the DELETED and INSERTED virtual tables.
Rule 2
When working with LinqToEntities services, UPDATED(columnname) is virtually useless.
Rule 3
Since UPDATED(columnname) is useless, the fallback is to do an INNER JOIN between the DELETED and INSERTED tables and compare column values.
Rule 4
Comparing column values need to account for the possibility of NULLs. On SQL Server, use ISNULL(columnname, default)
Rule 5
Seriously consider this – Linq2Entities services have a Changes property that may be useful in place of triggers.
Example:
Dim oldEquipmentPart As EquipmentPart = CType( _
Me.ChangeSet.ChangeSetEntries.Single( _
Function(e) e.Entity Is currentEquipmentPart).OriginalEntity,
EquipmentPart)
About this entry
You’re currently reading “ Debugging SQL Server Triggers ,” an entry on Chui's Counterpoint
- Published:
- 12.23.10 / 5pm
- Category:
- Engineering notes, SQL Server
Comments are closed
Comments are currently closed on this entry.