Comments posted to this topic are about the item Cross Database Context
Follow me on Twitter: http://www.twitter.com/way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
Hall of Fame
I use CONTEXT_INFO() regularly to "disable" triggers just for one session (e.g. migration scripts or bigger updates that should not touch the history tables / updated_at / _by columns or whatever the triggers do)
To do this, every trigger starts with a
IF @@ROWCOUNT = 0 OR CONTEXT_INFO() = 0x1000 RETURN;
(0x1000 is just a random number we agreed to it, theoretical you could use every other number).
And in the migration scripts I simply use
SET CONTEXT_INFO 0X1000
when I want / need to skip the trigger.
PS: of course this works only for AFTER triggers, if you have an INSTEAD OF trigger, you must not RETURN when CONTEXT_INFO() is set, you would need to do the regular INSERT / UPDATE / DELETE instead and skip only that parts, that does additional checks / auditing etc.
God is real, unless declared integer.
Viewing 2 posts - 1 through 1 (of 1 total)