34,838
社区成员




create trigger Hr_Employ_t
on Hr_Employ for update
AS
IF @@ROWCOUNT=0
RETURN
begin
--不需要賦值
update h
set OrganID=i.OrganID,DeptID=i.DeptID,ResumeID=i.ResumeID,PostID=i.PostID,PostGrade=i.PostGrade,PayID=i.PayID,PayGrade=i.PayGrade,Name=i.FullName,Sex=i.Sex,brithday=convert (datetime,default05)
............
from Hr_ArchiveM AS h,INSERTED AS i
where ArchiveID=i.EmployID
AND
(OrganID!=i.OrganID or DeptID!=i.DeptID or............)
end
create trigger Hr_ArchiveM_t
on Hr_ArchiveM for update
as
IF @@ROWCOUNT=0
RETURN
begin
update Hr_Employ
set OrganID=i.OrganID,DeptID=i.DeptID,..............
FROM Hr_Employ h,INSERTED i
where EmployID=i.ArchiveID
AND
(OrganID!=i.OrganID OR DeptID!=i.DeptID OR ..........)
end
create table tb1(id int,col1 int,col2 int)
insert into tb1 select 1,5,8 union all select 2,10,29
create table tb2(id int,col1 int,col2 int)
insert into tb2 select 1,5,8 union all select 2,10,29
go
create trigger ut2
on tb1
after update
as
begin
if @@NESTLEVEL<=1
update tb2 set col1=b.col1,col2=b.col2 from tb2 inner join inserted b on tb2.id=b.id
end
go
create trigger ut1
on tb2
after update
as
begin
if @@NESTLEVEL<=1
update tb1 set col1=b.col1,col2=b.col2 from tb1 inner join inserted b on tb1.id=b.id
end
go
update tb1 set col1=22 where id=1
go
select * from tb2
go
drop table tb1,tb2