求级联更新触发器
问题
表Department中的字段DepartmentName值发生改变时,同步表Waybill中的字段TransferDepartmen值也跟着改变,用触发器如何实现?
[解决办法]
create trigger tri_u
on Department
after update
as
begin
update a
set DepartmentName=t.DepartmentName_new
from Waybill a
inner join
(select b.DepartmentName as DepartmentName_old,a.DepartmentName as DepartmentName_new
from inserted a
inner join deleted b on a.DepartmentID=b.DepartmentID -->Department表更新时,更新前与更新后关联
)t
on a.DepartmentName=t.DepartmentName_old
end