Trigger that updates just the inserted row

前端 未结 2 1875
醉话见心
醉话见心 2020-12-30 03:54

I\'m trying to create a simple trigger using TSQL (or SQL Server 2008). The problem is: my current trigger is updating the entire table. This was fine for a while, but now t

2条回答
  •  一个人的身影
    2020-12-30 04:01

    If it is necessary to use a trigger here at all I would use an INSTEAD OF trigger to adjust the values pre-insert and avoid the need to JOIN back onto the base table and Update them afterwards.

    CREATE TRIGGER trig_MyPplUpdate
    ON [Persons]
    INSTEAD OF INSERT
    AS
      BEGIN
          INSERT INTO Persons
          SELECT foo,
                 bar,
                 CASE
                   WHEN Len(MyFile) >= 60 THEN MyFile
                 END
          FROM   Inserted
      END  
    

提交回复
热议问题