Problem with Trigger/View

  • I got a view that gest information från a certain table.  Then i got a trigger that should copy new information from this view to a specific table.  How should this trigger know when new information has been inserted in the View?

    CREATE TRIGGER copyRow

    ON person_View

    INSTEAD OF INSERT

    AS

    BEGIN

    INSERT into kontakt (nr, telefon, adress)

    values ('2', '3', '4')

    commit transaction

    END

  • If you're asking how you get the just inserted rows, have a look in Books Online for details of the inserted and deleted tables.

    the inserted table will contain the ust inserted rows. It will have all teh columns of the base table/view.

    INSERT into kontakt (nr, telefon, adress)

    SELECT nr, telefon, adress FROM inserted

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply