小弟我是个初学者,要处理这个业务,触发器如何写

我是个菜鸟,要处理这个业务,触发器怎么写?
现有2张表分别为表1和表2,当表2中有数据插入时,表1的状态更新为1,现在要实现的是将表1的某字段信息更新至表2的某字段中,如何处理?
------解决方案--------------------
引用:
Quote: 引用:

Quote: 引用:

Quote: 引用:

Quote: 引用:

Quote: 引用:

Quote: 引用:

Quote: 引用:

Quote: 引用:

可能是我的处理思路有问题,我还是具体说下我的需求。现在有4张表分别为a(finterid,forgppointerid,fmrpclosed),b(finterid),c(finterid,fentryid,fuse),d(fplanorderinterid,fsourceentryid,fnote),其中
d.fplanorderinterid=a.finterid 
and a.forgppointerid=c.finterid 
and c.finterid=b.finterid 
and d.fsourceentryid=c.fentryid
现在做的是:前台操作a表对应单据时,后台会在d表中生成一条记录,随后,a.fmrpclosed=1,在d表生成的记录中需要把c表的fnote带到d表的fuse中。
我现在有两种思路,一种是直接通过c表更新d,一种是通过中间表a关联c表更新d,不晓得那种方法可行,请大家给我指点指点,不胜感激。


就是在插入a表的时候,直接update d表,

也就是第2种方法吧,通过中间表a关联c表更新d


不是在插入a时生成d表记录,而是a表对应前台单据有个按钮事件,当事件结束后,有两个结果,一个是把a表fmrpclosed改为1,一个是在d表中产生新的记录。


哦,你的意思是,事件结束的时候,触发把c表的fnote带到d表的fuse中


是的,具体怎么实现?


那事件结束有什么标志吗,或者说事件结束,就会插入数据?


可以认为当a.fmrpclosed=1时代表事件结束,然后在更新d表字段。


那这个a.fmrpclosed=1 是有一个update操作吗


是的。


大概就是这样:
create trigger dbo.trigger_xx_update
on dbo.a
for update
as
begin

if update(fmrpclosed) and exists(select 1 from inserted where fmrpclosed = 1)
begin

update d
set fuse = c.fnote
from inserted a,b,c
where 
d.fplanorderinterid=a.finterid 
and a.forgppointerid=c.finterid 
and c.finterid=b.finterid 
and d.fsourceentryid=c.fentryid


end
go