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
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
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
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
for update
as
if update(course_id)
begin
update teacher_info
set ourse_id=(select course_id from inserted)
end
go
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
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