触发器问题

tmyu 2003-11-23 06:53:14
请问,
有两个表,我在a表加了个触发器,当有插入操作时,修改b表中total的值,但是修改的值要与a中插入的用户名称对应。该怎么做?
a表
id user price
1 tt 10
2 ee 20
3 ee 10--新插入的行
b表
id user total
1 ee 20--我要用触发器修改加上新插入的值“10”使ee用户变成30
2 tt 10
...全文
22 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
tmyu 2003-11-23
  • 打赏
  • 举报
回复
谢谢
friendliu 2003-11-23
  • 打赏
  • 举报
回复
create trigger on a
for insert
as
begin
declare @tt int
select @tt=sum(a.price) from a ,inserted c where a.user=c.user
update b set total=@tt from inserted c where c.user=b.user
end
friendliu 2003-11-23
  • 打赏
  • 举报
回复
create trigger on a
for insert
as
begin
declare @tt int
select @tt=sum(a.price) from a ,inserted c where a.user=c.user
update b set total=@tt from inserted c,where c.user=b.user
end

34,499

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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