mssql 触发器代码
create trigger depart_update
on depart
for update
as
begin
update t set t.部门号=i.部门号 from worker t, inserted i ,deleted d where t.部门号=d.部门号
endcreate trigger worker_delete
on worker
for delete
as
begin
delete t from salary t, deleted d where t.职工号=d.职工号
end
/*
在表depart上创建一个触发器depart_update,当更改部门号时同步更改worker表中对应的部门号;
在表worker上创建一个触发器worker_delete,当删除职工记录时同步删除salary表中对应职工的工资记录;
*/
时间: 2024-10-13 10:40:51