Question

I have a SQL Server 2012 database that is being Published for replication and a pull Subscription defined on another server. I have a Trigger that I need executed at the Subscriber end, however the source database is supported by a third party so to decrease the chance of them unwittingly blowing away my Trigger by doing table maintenance I defined the Trigger on the Publisher and set the Article option for Copy User Triggers to True.

That works okay, but what I don't want is for the Trigger to execute at the Publisher. (This is a reverse situation to using the NOT FOR REPLICATION option.) I've currently achieved this by wrapping the Trigger logic in a hard-coded test on @@SERVERNAME but we upgrade servers company-wide every 5 years or so and it is always a pain having things break that are hard-coded to the old names.

Is there a system view or something I can test against instead that will say "This database got here via a pull subscription"?

Thanks

Wayne Ivory

Was it helpful?

Solution

Yes, this can be done by adding the trigger to the Subscriber using a post-snapshot script. Have a look at Execute Scripts Before and After the Snapshot is Applied. This way there will be no dependency on a server name and the trigger will only exist at the Subscriber.

OTHER TIPS

Maybe the better option was not to have triggers at the publisher side in the first place but only at subscriber side. Or you can disable triggers at publisher side through some script.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top