触发器实例

ALTER TRIGGER tgr_mainrequest_update

on tbMain_Request

for update

as

    --declare @old_loc_id int ,@old_req_no int

    --declare @new_loc_id int,@new_req_no int

   

 --   select @old_loc_id=location_id,@old_req_no =request_no from deleted

 --   select @new_loc_id=location_id,@new_req_no =request_no from inserted

  

   if update(location_id)

    begin

        update tbSub_Request set location_id =inserted.location_id,location_invoice=inserted.location_id

        from deleted

        inner join inserted on inserted.request_no=deleted.request_no

        inner join tbSub_Request on tbSub_Request.location_id=deleted.location_id and tbSub_Request.request_no=deleted.request_no

    end

go

 

当修改主单的 location_id 时,修改 子单的 location_id

原文地址:https://www.cnblogs.com/withoutaword/p/2549427.html