SQL Server 触发器 当一个字段值修改时,修改当前数据其他字段值

时间:2025-03-19 07:31:14
create  TRIGGER testtrigger --触发器名称
   on tb  --表名
  after update --更新触发
  as
  if update (column1)  --当column1字段被更新时,才会触发此触发器
BEGIN
    SET NOCOUNT ON;
    DECLARE @a VARCHAR (20)  --定义变量
    SET @a = (SELECT 
    FROM
        deleted d,
        inserted i
    WHERE
         = 
) --变量赋值 ,找到对应更新的那一行。
    update  tb  set  test = 'g2' where ida = @a --执行的操作
end
create  TRIGGER  [dbo].[billtrigger]  
   on [dbo].[ICStockBill] 
  after update --更新触发
  as
  if update (FStatus)  --当FStatus字段被更新时,才会触发此触发器
BEGIN
    SET NOCOUNT ON;
    DECLARE @a VARCHAR (20)  --定义变量
    SET @a = (SELECT
	
    FROM
        deleted d,
        inserted i
    WHERE
         = 
) --变量赋值 ,找到对应更新的那一行。
update  ICStockBillEntry set  FEntrySelfB0457 = 
(select   from ICInventory b 
where    =  
and  =)
where  finterid =@a
end