一個更新的觸發,大家幫我。

vfork 2006-03-18 10:27:47
table A,table B

B的flag初始為0,
當flag更新為1時,A.Amount=A.Amount+B.Amount
當flag更新為0時,A.Amount=A.Amount-B.Amount

我寫的錯誤的觸發如下:
CREATE TRIGGER In_update_store ON [dbo].B
FOR UPDATE
AS
if update(flag)
begin
update A set A.amount=A.amount-A.Bmount from inserted B where A.id=B.Mtid and B.flag=0
update A set A.amount=A.amount+B.Amount from inserted B where A.id=B.Mtid and B.flag=1
end
...全文
76 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
vfork 2006-03-18
  • 打赏
  • 举报
回复
不是,flag=1觸發結果正常,但是在delphi裡報錯,(刪除觸發就在delphi中不報錯了)
flag=0時候,結果不正常,而且也報錯。
huailairen 2006-03-18
  • 打赏
  • 举报
回复

update A set A.amount=A.amount-A.Bmount from inserted B where A.id=B.Mtid and B.flag=0 中-----------》A.amount-A.Bmount 是不是写错了啊
应该是A.Amount-B.Amount 吧
vfork 2006-03-18
  • 打赏
  • 举报
回复
樓上的再干什麼?
$扫地僧$ 2006-03-18
  • 打赏
  • 举报
回复
create table A
(
id int,
Amount int
)

create table B
(
mid int,
flag int,
Amount int
)

insert A select 1,0
insert B select 1,0,10


CREATE TRIGGER In_update_store ON [dbo].B
FOR UPDATE
AS
if update(flag)
begin
update A set A.amount=A.amount-B.amount from inserted B where A.id=B.Mid and B.flag=0
update A set A.amount=A.amount+B.Amount from inserted B where A.id=B.Mid and B.flag=1
end


update B set flag=1 from B where Mid=1

select * from A
select * from B

34,588

社区成员

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

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