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

后端 未结 7 818
一向
一向 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 23:13

    Yea...having an additional step to update a table in which you can set the value in the inital insert is probably an extra, avoidable process. Do you have access to the original insert statement where you can actually just insert the part_description into the part_description_upper column using UPPER(part_description) value?

    After thinking, you probably don't have access as you would have probably done that so should also give some options as well...

    1) Depends on the need for this part_description_upper column, if just for "viewing" then can just use the returned part_description value and "ToUpper()" it (depending on programming language).

    2) If want to avoid "realtime" processing, can just create a sql job to go through your values once a day during low traffic periods and update that column to the UPPER part_description value for any that are currently not set.

    3) go with your trigger (and watch for recursion as others have mentioned)...

    HTH

    Dave

    0 讨论(0)
提交回复
热议问题