I would like to know if there is anyway I can add a trigger on two tables that will replicate the data to the other.
For example:
-
I have a two users tables, users_V1 and users_V2, When a user is updated with one of the V1 app, it activate a trigger updating it in users_V2 as well.
-
If I want to add the same trigger on the V2 table in order to update the data in V1 when a user is updated in V2, will it go into an infinite loop? Is there any way to avoid that.
I don’t recommend explicitly disabling the trigger during processing – this can cause strange side-effects.
The most reliable way to detect (and prevent) cycles in a trigger is to use
CONTEXT_INFO().Example:
See this link for a more detailed example.
Note on
CONTEXT_INFO()in SQL Server 2000:Context info is supported but apparently the
CONTEXT_INFOfunction is not. You have to use this instead: