?
Solved

insert trigger fired on replication

Posted on 2004-09-15
5
Medium Priority
?
460 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 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Ready to get certified? Check out some courses that help you prepare for third-party exams.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
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.
Suggested Courses

807 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