Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2003
    Posts
    100

    Red face Unanswered: how do I get a trigger just to copy the inserted row.

    HI I have a trigger which I want to copy any rows in the MSmerge_history into a archieve table. I am using this trigger:

    CREATE TRIGGER History_replication ON
    [dbo].[MSmerge_history]
    FOR INSERT
    AS
    INSERT [dbo].[MSmerge_history_archive]
    (
    agent_id,
    runstatus,
    start_time,
    [time],
    duration,
    comments,
    delivery_time,
    delivery_rate,
    publisher_insertcount,
    publisher_updatecount,
    publisher_deletecount,
    publisher_conflictcount,
    subscriber_insertcount,
    subscriber_updatecount,
    subscriber_deletecount,
    subscriber_conflictcount,
    error_id,
    [timestamp] ,
    updateable_row
    )
    SELECT
    agent_id,
    runstatus,
    start_time,
    [time] ,
    duration,
    comments,
    delivery_time,
    delivery_rate,
    publisher_insertcount,
    publisher_updatecount,
    publisher_deletecount,
    publisher_conflictcount,
    subscriber_insertcount,
    subscriber_updatecount,
    subscriber_deletecount,
    subscriber_conflictcount,
    error_id,
    [timestamp],



    How this copy the entire contence of the table into the archive each time someone insert a row. How do I get it to only insert the row which had triggered the insert? Ed

  2. #2
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    CREATE TRIGGER History_replication ON
    [dbo].[MSmerge_history]
    FOR INSERT
    AS
    INSERT [dbo].[MSmerge_history_archive]
    (
    agent_id,
    runstatus,
    start_time,
    [time],
    duration,
    comments,
    delivery_time,
    delivery_rate,
    publisher_insertcount,
    publisher_updatecount,
    publisher_deletecount,
    publisher_conflictcount,
    subscriber_insertcount,
    subscriber_updatecount,
    subscriber_deletecount,
    subscriber_conflictcount,
    error_id,
    [timestamp] ,
    updateable_row
    )
    SELECT
    agent_id,
    runstatus,
    start_time,
    [time] ,
    duration,
    comments,
    delivery_time,
    delivery_rate,
    publisher_insertcount,
    publisher_updatecount,
    publisher_deletecount,
    publisher_conflictcount,
    subscriber_insertcount,
    subscriber_updatecount,
    subscriber_deletecount,
    subscriber_conflictcount,
    error_id,
    [timestamp]
    FROM inserted


    Inserted is virtual table used by triggers.
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  3. #3
    Join Date
    Jul 2003
    Posts
    100

    Talking

    Excellent thanks I've got that working now, Ed

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •