有两个表:a,b
a中字段:
userID RegistryDTb中字段:
UserID Quantity触发器功能:
当b表别更新时,把b表中的quantity字段设置为100。条件时a表中RegistryDT=NULL,
a中userid和b中userid关联
请问这个触发器怎么写?
a中字段:
userID RegistryDTb中字段:
UserID Quantity触发器功能:
当b表别更新时,把b表中的quantity字段设置为100。条件时a表中RegistryDT=NULL,
a中userid和b中userid关联
请问这个触发器怎么写?
begin
update b
set Quantity = 100
from inserted
where inserted.userid = b.useridupdate a
set RegistryDT=NULL
from inserted
where inserted.userid = a.userid
end
对不起,我说不清楚。
表b别更新时,扫描a表中RegistryDT的值为空的,就把b表中字段quantity的值设置为100。
意思就是:(set quantity=100 where a.registryDT=NUll)
update b
set quantity=100
from inserted,
a
where b.userid = inserted.userid
and a.userid = b.userid
and a.registryDT is NULL
谢谢您!
我在b的触发器是这样写的:
CREATE TRIGGER PresentSM ON dbo.SendPeriod
FOR Update
AS
UPdate SendPeriod
set SendPeriod.Send_quantity=1000000 from inserted,blocuser
where inserted.user_id=blocuser.user_id
and BlocUser.User_id=SendPeriod.User_id
and blocuser.registrydt is null当a中RegistryDT的值为空时,直接在SQL Server表中修改quantity的值,或者在Delphi里用
下列语句修改时都正确!
t.Edit;
t.FieldByName('send_quantity').AsInteger:=t.FieldByName('send_quantity').AsInteger+1;
try
t.Post;
except
showmessage(t.FieldByName('send_quantity').AsString);
end;
但是当RegistryDT的值为非空时.直接在SQL Server表中修改quantity的值正确,但在Delphi里就报错.
Error: (无法为更新行集定位:一些值可能已在最后读取后改变)
这是为什么?
还有Inserted表是什么来头?