sql server触发器中增删改判断

时间:2023-11-23 21:00:38

触发器生效逻辑

在Before或者After之后使用INSERT,DELETE,UPDATE

触发器内情况判断

  • 插入
    if exists(select 1 from inserted) and not exists(select 1 from deleted)
  • 删除
    ELSE if exists(select 1 from deleted) and not exists(select 1 from inserted)
  • 更新
    ELSE if exists(select 1 from deleted) and exists(select 1 from inserted)