CREATE TRIGGER xiuga ON 同学表
after update            
AS
if (select count(1) from inserted)>1
return --不支持更新多條記錄
update a 
set 编号=b.编号
from 宿舍表 a cross join inserted b 

解决方案 »

  1.   

    CREATE TRIGGER xiuga ON 宿舍表
    after update            
    AS
    if (select count(1) from inserted)>1
        return --不支持更新多條記錄
    update a 
    set 宿舍编号=b.编号
    from 同学表 a cross join inserted b 
      

  2.   

    建議用級聯
    alter table 同学表 add constraint FK_同学表_1 foreign key (宿舍编号) references 宿舍表(编号) on update cascade 
      

  3.   

    create trigger 表 on 表
    for insert 
    as 
    begin
    '''''
    end
      

  4.   

    where exists(select 1 from deleted where 编号=a.宿舍编号)--触发器加上这个条件。。
    只支持一条一条的更新,用级联没限制
      

  5.   

    --请问高手那个用游标怎么搞啊???
    --下面那个是未完成的能帮忙完成一下吗??谢谢了啊~~
    CREATE TRIGGER xiuga ON 同学表
    after update
    AS
    IF UPDATE (编号)
    BEGIN
    declare @oldno varchar(3),@newno varchar(3)
    select @oldno=编号 from deleted
    select @newno=编号 from inserted
    declare nostu insensitive cursor for select * from 同学表 where 宿舍编号=@oldno 
    open nostu
    if @@cursor_rows =0 print 'no stus'
    else
    fetch next from nostu
    select from 编号=@newno

    while @@fetch_status=0 
    fetch next from nostu
    end
    GO