?
Solved

insert trigger fired on replication

Posted on 2004-09-15
5
Medium Priority
?
449 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

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.
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Suggested Courses

741 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