create trigger tra_a on school for update as
declare @newarea_id int,
@oldarea_id int,
@i_school_id int
begin
select @olearea_id=i_area_id from deleted
select @newarea_id=i_area_id,@i_school_id=i_school_id from inserted
if(@newarea_id=@oldarea_id)
begin
return
end
if exists(select i_school_id=@i_school_id from student)
begin
update student set i_area_id=@newarea_id where i_school_id=@i_school_id
end
if exists(select i_school_id=@i_school_id from teacher)
begin
update teacher set i_area_id=@newarea_id where i_school_id=@i_school_id
end
if exists(select i_school_id=@i_school_id from class)
begin
update class set i_area_id=@newarea_id where i_school_id=@i_school_id
end
end
declare @newarea_id int,
@oldarea_id int,
@i_school_id int
begin
select @olearea_id=i_area_id from deleted
select @newarea_id=i_area_id,@i_school_id=i_school_id from inserted
if(@newarea_id=@oldarea_id)
begin
return
end
if exists(select i_school_id=@i_school_id from student)
begin
update student set i_area_id=@newarea_id where i_school_id=@i_school_id
end
if exists(select i_school_id=@i_school_id from teacher)
begin
update teacher set i_area_id=@newarea_id where i_school_id=@i_school_id
end
if exists(select i_school_id=@i_school_id from class)
begin
update class set i_area_id=@newarea_id where i_school_id=@i_school_id
end
end