create trigger cfq on lesson_info
for update
asif @@rowcount=0 returnif update(ourse_id)
 begin
  update a set a.ourse_id=b.ourse_id from teacher_info a,inserted b where a.id=b.id
 end
go

解决方案 »

  1.   

    create triger ttt on dbo.lesson_info
    after update
    as 
    begin
        if exists(select course_id from inserted)
        update teacher_info set course_id=(select course_id from inserted) 
        where course_id=(select course_id from deleted)
    end
      

  2.   

    create trigger tr_lesson_info_update_course_id
    on lesson_info
    for update
    as
    if update(course_id)
      update teacher_info
      set course_id=i.course_id
      from inserted i,deleted d,teacher_info t
      where i.主键=d.主键                        --必须有主键才安全
      and d.course_id=t.course_id
    go
      

  3.   

    create trigger TR_lesson_info on lesson_info
    for update
    as
    if update(course_id)
     begin
      update teacher_info
        set ourse_id=(select course_id from inserted)
     end
    go
      

  4.   

    多谢大家,受别人的启发,我自己也写了一个.而且实验成功.看来有多种写法.
    create trigger teacher_update
    on
    lesson_info
    for update 
    as 
    declare 
      @old  varchar(20),
      @new  varchar(20)begin
       if  update(course_id)
           begin
                
               select @new =course_id from inserted
               select @old =course_id from deleted
                                    
               update teacher_info set name=@new where course_id=@old
           end
              
             end
      

  5.   

    create trigger t_update
    on esson_info 
    for update
    as 
      begin 
       if update(course_id)
         begin 
           update teacher_info set name = (select @course_id from inserted)
           where course_id=(select course_id from deleted )
         end