日期:2014-05-18 浏览次数:20459 次
create trigger tri_YGZW_YYCL on YGZW_YYCL for insert,update,delete as if not exists(select 1 from deleted) --insert begin insert into YGZW_YYCL_ZL select *,getdate(),0 from inserted end if not exists(select 1 from inserted) -- delete begin insert into YGZW_YYCL_ZL select *,getdate(),2 from deleted end else --update begin insert into YGZW_YYCL_ZL select *,getdate(),1 from inserted end go
------解决方案--------------------
create trigger tr_name on YGZW_YYCL for insert,update,delete as if update(id) or update(carID) or update(carColor) insert into YGZW_YYCL_ZL select *,getdate(),1 from inserted else begin if exists(select 1 from inserted) insert into YGZW_YYCL_ZL select *,getdate(),0 from inserted else insert into YGZW_YYCL_ZL select *,getdate(),2 from deleted end
------解决方案--------------------
if else 嵌套