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
after update
AS
if (select count(1) from inserted)>1
return --不支持更新多條記錄
update a
set 编号=b.编号
from 宿舍表 a cross join inserted b
after update
AS
if (select count(1) from inserted)>1
return --不支持更新多條記錄
update a
set 宿舍编号=b.编号
from 同学表 a cross join inserted b
alter table 同学表 add constraint FK_同学表_1 foreign key (宿舍编号) references 宿舍表(编号) on update cascade
for insert
as
begin
'''''
end
只支持一条一条的更新,用级联没限制
--下面那个是未完成的能帮忙完成一下吗??谢谢了啊~~
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