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

后端 未结 7 849
一向
一向 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:09

    create or replace 
    TRIGGER triggername BEFORE INSERT  ON 
    table FOR EACH ROW 
    BEGIN
    /*
    Write any select condition if you want to get the data from other tables
    */
    :NEW.COLUMNA:= UPPER(COLUMNA); 
    --:NEW.COUMNa:= NULL;
    END; 
    

    The above trigger will update the column value before inserting. For example if we give the value of COLUMNA as null it will update the column as null for each insert statement.

提交回复
热议问题