当行政部门表中的行政部门名称字段改变时职员表中各职员的行政部门名称相应改变
CREATE TRIGGER trg_u_行政部门名称 ON [dbo].[行政部门表]
FOR INSERT, UPDATE, DELETE
AS
declare @num_rows int
select @num_rows=@@rowcount
if @num_rows=0
return
if update(行政部门名称)
begin
update 职员表 set 行政部门名称= 行政部门名称
from inserted
where 行政部门名称=行政部门名称
end
return
请各位帮忙改一下!
CREATE TRIGGER trg_u_行政部门名称 ON [dbo].[行政部门表]
FOR INSERT, UPDATE, DELETE
AS
declare @num_rows int
select @num_rows=@@rowcount
if @num_rows=0
return
if update(行政部门名称)
begin
update 职员表 set 行政部门名称= 行政部门名称
from inserted
where 行政部门名称=行政部门名称
end
return
请各位帮忙改一下!
begin
update 职员表 set 行政部门名称= B.行政部门名称
from 职员表 A ,inserted B, DELETED C
where A.行政部门名称=C.行政部门名称 AND C.ID=B.ID
end
if update(行政部门名称)
begin
update 职员表 set 行政部门名称= B.行政部门名称
from 职员表 A, inserted B
where A.行政部门ID = B.行政部门ID
end