Insert Trigger with multiple Rows

  • Hello,

    I am trying to conceptualize how to create a trigger that can insert multiple rows.

    I have a web form that will INSERT INTO a table multiple email addresses. When that INSERT happens, I want to create a new record in another table (by Trigger).

    Can someone help me understand how this is possible?

  • Within the trigger, something like

    INSERT INTO AnotherTable

    SELECT <whatever columns needed> 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
  • Key point here is to avoid putting INSERTED data into VARIABLES!! This is a CRITICAL FLAW because triggers fire once per BATCH, not PER ROW! Very common mistake.

    I actually had a client go out of business because of this - and I TOLD THEM IT WAS GOING TO HAPPEN over a year before it did!! Very sad.

    Best,
    Kevin G. Boles
    SQL Server Consultant
    SQL MVP 2007-2012
    TheSQLGuru on googles mail service

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

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