March 3, 2023 at 12:00 am
Comments posted to this topic are about the item Cross Database Context
March 3, 2023 at 9:44 am
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)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy