Solved

insert trigger fired on replication

Posted on 2004-09-15
5
425 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

813 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