create trigger test on 表1
for insert,update,delete --如果不同步删除,就不要,delete
as
if update(FInterID)  ----判断字段FInterID是否做了修改
begin
    if exists(select * from inserted)  ---判断是否新增了记录。
         if exists(select * from deleted)--判断是否删除了记录。
         begin        --如果Inserted表和deleted表都有记录说明是执行了修改操作,因           --为SQL修改记录时先把原记录删除,再新增一条新的记录。
             --修改的情况
             select id=identity(int,1,1),FInterID,aa into #i from inserted   
                ----将Inserted表的内容存入临时表#i中并为#i表添加一个
                --自动新增的标识字段。
             select id=identity(int,1,1),FInterID into #d from deleted
             update t2 set FInterID=b.FInterID,aa=b.aa
                  from t2 a
                  ,(select i.FInterID,i.aa,d.FInterID as dFInterID from #i i,#d d where i.FInterID=d.FInterID) b
                  where a.FInterID=b.dFInterID
         end
         else
         --新增的情况
         insert into t2 select FInterID,1,aa from inserted
    else
        --删除的情况
        delete from t2 where FInterID in (select FInterID from deleted) 
        --删除t2中所有 FInterID 与 表1 中被删除记录的FInterID相同的记录。
end