|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-04-09 : 09:29:53
|
| Alex writes "MS SQL 2000 is failing to replicate my triggers. I have a test table, zzzTEST, that I am replicating. zzzTEST looks like this...CREATE TABLE [dbo].[zzzTEST] ( [test_pk] [int] IDENTITY (1, 1) NOT NULL , [field1] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [field2] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [field3] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [msrepl_tran_version] [uniqueidentifier] NOT NULL ) ON [PRIMARY]GOALTER TABLE [dbo].[zzzTEST] WITH NOCHECK ADD CONSTRAINT [DF__zzzTEST__msrepl___392B6C00] DEFAULT (newid()) FOR [msrepl_tran_version], CONSTRAINT [PK_zzzTEST] PRIMARY KEY CLUSTERED ( [test_pk] ) WITH FILLFACTOR = 95 ON [PRIMARY] GOI then have two triggers that I have created for this table...CREATE trigger zzzTEST_Update on dbo.zzzTESTfor update asdeclare @test_pk int, @currentuser int, @newstatus char(3), @oldstatus char(3), @pk_listenlog int, @date datetimeSELECT @test_pk = test_pkFROM insertedWHERE test_pk in (select test_pk from inserted)if update ( field1 )update zzzTEST set field2 = ('UPDATING'), field3 = 'PROCS' where test_pk in (select test_pk from inserted)CREATE TRIGGER zzzTEST_Insert on [dbo].[zzzTEST] FOR INSERT ASdeclare @test_pk int, @currentuser int, @newstatus char(3), @oldstatus char(3), @pk_listenlog int, @date datetimeSELECT @test_pk = test_pkFROM insertedWHERE test_pk in (select test_pk from inserted)if update ( field1 )update zzzTEST set field2 = ('INSERTING'), field3 = 'PROCS' where test_pk in (select test_pk from inserted)When I replicate my two databases, I am only replicating one table, zzzTEST, as a transactional replication, with immediate updating. Before I start the replication, I create the zzzTEST table and its triggers on the subscriber database. When I create the publication, I select zzzTEST as the only table to be replicated, and I select from the Table Article Properties, the Snapshot tab, where I select "Use Trigger" from Copy objects to destination. When my replication is finished, I create a pull-subscription to it, and run the snapshot agent. The agent creates a snapshot of my publisher's table, zzzTEST, and all its data, into the subscriber database. However, since I created the triggers zzzTEST_Update and zzzTEST_Insert on my subscriber database before replication, I should expect them to still remain. zzzTEST_Update remains, but zzzTEST_Insert is over-written. Now I have 4 triggers where before I had 2, and they are...trg_MSsync_del_zzzTESTtrg_MSsync_ins_zzzTESTtrg_MSsync_upd_zzzTESTzzzTEST_UpdateI cannot get my replication to work properly, b/c I cannot insert data into the subscription table, zzzTEST. I continuously get the following errors. "Another user has modified the contents of this table or view; the database row you are modifying no longer exists in the database. Database error:'[Microsoft][ODBC SQL Server Driver][SQL Server]Updatable Subscriptions: Rows do not match between Publisher and Subscriber. Run the Distribution Agent to refresh rows at the Subscriber. [Microsoft][ODBC SQL Server Driver][SQL Server]Updatable Subscriptions: Rolling back transaction."If anyone can please offer some advice, you just may help me save my job and help put food on my table. Thanks for your time. Alex" |
|
|
setbasedisthetruepath
Used SQL Salesman
992 Posts |
Posted - 2002-04-09 : 10:01:34
|
Generally speaking, you don't want triggers to come over in replication. Whatever data modifications result from triggers on the published articles are sent over in exactly the same fashion as changes occurring directly on the published articles themselves. You don't need the triggers on the subscriber to make that work ( particularly if you're using transactional [one-way] replication ).If you have some kind of special need, then post additional comments and I'll do my best ... .setBasedIsTheTruepath<O> |
 |
|