Replicating Triggers

By Chris Miller on 14 August 2000 | Tags: Replication , Triggers


Miles writes "An associate of mine and I were attempting to include database triggers that we have developed in the replication of one of our databases. I had the idea of creating a trigger on the syscomments table so that whenever a trigger was updated on the master dB, all the other replicated databases would be updated with the newest version of the trigger. To our dismay, we were not allowed to create triggers on the system table. Is there any other way to do this? Thanks in advnace for your help!

At this time, in this version of SQL Server (7.0) you're not allowed to replicate triggers. Sorry, not the answer you were looking for.

Now...here's one way to do it. I'd suggest using a polling-application, or manually triggering the replication, and then using a remote call to xp_cmdshell to ISQL. Set the polling stored proc up to query something that contains the checksums from syscomments. Grab the actual trigger text from syscomments and build an ISQL query string, and then do a remote call via linked server to xp_cmdshell:

exec @retval = FooServer.master.dbo.xp_cmdshell 'isql -Usa -P -Q "create trigger blah blah blah"'

You can use the value in @RetVal to make sure the query actually ran. Books Online has a list of the return codes and other parameters (integrated security).

This is pretty typical of my 'sledgehammer-based' problem solving technique, and is overall a pretty evil way to do a lot of really nasty things. Be careful.


rocketscientist.


Related Articles

Using DDL Triggers in SQL Server 2005 to Capture Schema Changes (13 August 2007)

Replicating SQL Server 2000 across Heterogeneous Databases (24 August 2003)

Horizontal and Vertical Partitioning in Replication (30 January 2003)

Database Journal - SQL Server section (18 December 2002)

Audit Triggers for SQL Server (8 May 2002)

Code to find out the statement that caused the trigger to fire! (16 April 2002)

An Introduction to Triggers -- Part II (4 November 2001)

An Introduction to Triggers -- Part I (30 April 2001)

Other Recent Forum Posts

. How to Save Big on Temu with Coupon Code [act892435] in the USA (47m)

Limited-Time USA Offer: Temu Coupon Code {act892435} for Great Savings (52m)

Temu coupon code $100{act892435}off for USA customers (56m)

Temu Canada Black Friday Sale: 90% Off {acs540599} with Free Shipping 2024 (63m)

Temu Coupon Code $100 off [acr639380] Get 30% Off On Your First Order (106m)

Temu Coupon Code Romania [acr639380] 100€ Reducere (108m)

Temu Kod Za Popust [acr639380] 40% Popusta Za Postojeće Kupce (109m)

Temu Coupon Code 2024 for Existing Customers (acr639380) (113m)

- Advertisement -