帮忙写一个触发器

livi 2003-07-09 03:28:14
table1(id(主键),ii(smallint) )
table2(id, id1,qty) ,
table3(id1,total)

table1通过id与table2相关联,table2通过id1与table3相关联,当ii被update 为1 时 ,用table2里每一个与id相同的记录更新table3中的total(total=total+qty)

不知说清楚没有?
谢谢!
...全文
73 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
livi 2003-07-09
  • 打赏
  • 举报
回复
谢谢大家!
bomber2001 2003-07-09
  • 打赏
  • 举报
回复
Creat Trigger trg_update ON table1
FOR update AS
update table3
set total=total+(select sum(qty) from table2 b where a.id=b.id ) from table3 a,table2 b
where a.id in (select id from table1)

ropriest(馆主) 不错啊,你的分数涨的真快啊,快要红星飘飘了
Varchar 2003-07-09
  • 打赏
  • 举报
回复
呵呵,楼上高明!!

ropriest 2003-07-09
  • 打赏
  • 举报
回复
TO Yang_(扬帆破浪)
怎么好象在CS一样,呵呵

go!

go!
ropriest 2003-07-09
  • 打赏
  • 举报
回复
Creat Trigger trg_update ON table1
FOR update AS
update table3
set total=total+(select sum(qty) from table2 b where a.id=b.id ) from table3 a,table2 b
where a.id in (select id from table1)
Yang_ 2003-07-09
  • 打赏
  • 举报
回复
create trigger tr_table1_update
on table1
for update
as
if update (ii)
update table3
set total=total+(select sum(qty) from table2 b where a.id1=b.id1 and b.id in (select id from inserted where ii=1)) from table3 a
where id1 in (select id1 from table2 where id in (select id from innserted where ii=1))

go

怎么这么拗口呢?


go
zx_ali 2003-07-09
  • 打赏
  • 举报
回复
update table3
set total=total+(select sum(qty) from table2 b where a.id=b.id ) from table3 a,table2 b
where a.id in (select id from table1)

611

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder DataWindow
社区管理员
  • DataWindow社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧