I have several tables that are updated through my application that return a lot of data or it is difficult to request changes. To get around this problem, I created a table "LastUpdated" with one row and has a trigger for these complex tables, which simply sets GetDate () to the corresponding column in the LastUpdated table:
CREATE TRIGGER [dbo].[trg_ListItem_LastUpdated] ON [dbo].[tblListItem] FOR INSERT, UPDATE, DELETE AS UPDATE LastUpdated SET ListItems = GetDate() GO
Thus, customers only need to query this table for the last updated value, and then decide whether they need to update their data from complex tables. Complex tables use snapshot isolation to prevent dirty reads.
On busy systems, approximately once a day, we get errors when writing or updating data in complex tables due to update conflicts in "LastUpdated". Since this happens in a statement executed by a trigger, a corrupted complex table does not save data. The following error is being recorded:
Snapshot isolation operation canceled due to update conflict. You cannot use snapshot isolation to access the table 'dbo.tblLastUpdated' directly or indirectly in the 'devDB' database to update, delete, or insert a row that has been modified or deleted by another transaction. Retry the transaction or change the isolation level for the update / delete statement.
What should I do in a trigger to prevent this failure? Can I use some kind of tooltip for the tooltip on the trigger to avoid this - or can I just ignore the errors in the trigger? Updating data in LastUpdated is not critical, but correctly saving data in complex tables.
This is probably something very simple that I forgot or do not know. As always, thanks for any info.
source share