Captured Technology

Updating a Table Without Firing the Trigger

Apr 09 2009

Updating a Table Without Firing the Trigger

Having a Trigger on a SQL Server table is a great feature that can keep data in sync and update records automatically when needed but what about those cases where you want to run an update command and don't want the trigger to fire. I came across a situation where an update timestamp on a record was being displayed on a web page and I wanted a specific date to show up. The easiest way to fix this issue was to disable the trigger, update the update timestamp on the record, and then enable to trigger. Here is the code:

 

DISABLE TRIGGER [dbo].[Document_Update] ON [Document]
 
UPDATE [Document]
   SET [update_timestamp] = '2009-04-01 10:00:00.950'
 WHERE document_filename like '%some_unique_value%'
 
ENABLE TRIGGER [dbo].[Document_Update] ON [Document]

Blog Directory

Latest technology news.
 Steve Patterson
 424  245478  11/17/2017

FaceBook

Translate

Sponsors





Blog Calendar

Categories