SQL Server - after insert trigger - update another column in the same table

后端 未结 7 824
一向
一向 2020-12-04 22:27

I\'ve got this database trigger:

CREATE TRIGGER setDescToUpper
ON part_numbers
 AFTER INSERT,UPDATE
AS
DECLARE @PnumPkid int, @PDesc nvarchar(128)

SET @Pnum         


        
7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-04 22:53

    It might be safer to exit the trigger when there is nothing to do. Checking the nested level or altering the database by switching off RECURSIVE can be prone to issues.

    Ms sql provides a simple way, in a trigger, to see if specific columns have been updated. Use the UPDATE() method to see if certain columns have been updated such as UPDATE(part_description_upper).

    IF UPDATE(part_description_upper)
      return
    

提交回复
热议问题