Solved

insert trigger fired on replication

Posted on 2004-09-15
5
422 Views
Last Modified: 2008-03-17
Hello

I have a trigger that fires when data is inserted into one table.  The database is published for merge replication and when the data is updated at the subscriber, the trigger fires again. How can I stop the trigger firing when the replication takes place?

Thank you in advance
Debs
0
Comment
Question by:debrafry
  • 3
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
OlegP earned 500 total points
ID: 12063960
CREATE TRIGGER trigger_name
ON { table | view }
[ WITH ENCRYPTION ]
{
    { { FOR | AFTER | INSTEAD OF } { [ INSERT ] [ , ] [ UPDATE ] }
        [ WITH APPEND ]
        [ NOT FOR REPLICATION ]
        AS
        [ { IF UPDATE ( column )
            [ { AND | OR } UPDATE ( column ) ]
                [ ...n ]
        | IF ( COLUMNS_UPDATED ( ) { bitwise_operator } updated_bitmask )
                { comparison_operator } column_bitmask [ ...n ]
        } ]
        sql_statement [ ...n ]
    }
}



NOT FOR REPLICATION

Indicates that the trigger should not be executed when a replication process modifies the table involved in the trigger.
0
 
LVL 6

Expert Comment

by:OlegP
ID: 12064119
I think that make changes is not problem for you.
( Enterprise Manager ->Right button click on table-> All tasks -> Manage triggers -> select Trigger -> ADD 'NOT FOR REPLICATION' befor 'AS' statement-> Apply)
0
 

Author Comment

by:debrafry
ID: 12064264
Hi

my current trigger now looks like this:

CREATE  trigger trgRegisteredContact
on dbo.tblContactPoint
for Insert NOT FOR REPLICATION
as
    declare @ID as uniqueidentifier
    --This selects pkCPID from the inserted table and assigns it to the variable  @ID
    select @id = pkCPID from inserted  
    insert into tblTopic (pkTPID, fkCPID,strTName, strDepartmentID, strOrigin, dtmCreated, dtmModified)
    values (Newid(), @id, 'Software','CS', 'Administrator', GetDate(),GetDate())
      
      update tblContactpoint
      set dtmCreated = Getdate(), dtmModified = Getdate()
      where pkCPID = @ID


However, unfortunately it has not solved the problem, any idea? Thanks
0
 
LVL 6

Expert Comment

by:OlegP
ID: 12065031
are you sure that trigger startup during replication?
try to add some test statment insert into a table(which at not replication plan) to trigger and check.
0
 

Author Comment

by:debrafry
ID: 12065476
Hi
Problem solved, Thank you for your help, I will award points to your first response.  Although I thought I'd changed the trigger that was on the subscriber, it appears that it had reverted to it's previous state without the NOT FOR REPLICATION statement.  
Having amended it again it now works correctly.

Many Thanks
Debs :-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now