我在表bd_Shipout建了个触发器后,程序更新保存的时候就出错 ,弹出record no found or changed by another user ;
删除了改触发器后,一切就正常了;
触发器的代码如下:Alter Trigger ShipOut_OutStore
on bd_shipout
for insert,update,delete
as
begin
--新增时插入
if not exists(select 0 from Deleted) and exists(select 0 from Inserted)
begin
insert into bd_intranout select cShipCoding,iMeCoding,cShipCode,dMakeDate,cShipOPCode,
cShipDepCoding,cShipPersonCoding,cExpCoding,dShipSdate,dShipDate,mMoney,
cDocRequire,cState,bShipSelect,bCreate,iSaleCID,cShipCusCoding,null,bSOSubmit,
iADFlag,cADPerson,iADRole,bNote,null from inserted where bOutStore=1
end
--编辑时修改
else if exists(select 0 from Deleted) and exists(select 0 from Inserted)
begin
update a set a.iMeCoding=b.iMeCoding,a.cInTranCode=cShipCode,a.dMakeDate=b.dMakeDate,
a.cInTranOPCode=cShipOPCode,a.cITDepCoding=cShipDepCoding,a.cITPersonCoding=cShipPersonCoding,
a.cInSaleCNCoding=cExpCoding,a.dInTranSDate=dShipSdate,a.dInTranDate=dShipDate,
a.mInTranMoney=mMoney,a.cITMemo=cDocRequire,a.cState=b.cState,a.bITSelect=bShipSelect,
a.bITCreate=bCreate,a.iITCidNum=iSaleCID,a.cITCusCoding=cShipCusCoding,a.bSubmit=bSOSubmit,
a.iADFlag=b.iADFlag,a.cADPerson=b.cADPerson,a.iADRole=b.iADRole,a.bNote=b.bNote
from bd_intranout a,inserted b where b.cShipCoding=a.cInTranCoding and b.bOutStore=1
end
--删除
else if exists(select 0 from Deleted) and not exists(select 0 from Inserted)
begin
delete from bd_intranout where cInTranCoding in (select cShipCoding from Deleted where bOutStore=1)
end
end
删除了改触发器后,一切就正常了;
触发器的代码如下:Alter Trigger ShipOut_OutStore
on bd_shipout
for insert,update,delete
as
begin
--新增时插入
if not exists(select 0 from Deleted) and exists(select 0 from Inserted)
begin
insert into bd_intranout select cShipCoding,iMeCoding,cShipCode,dMakeDate,cShipOPCode,
cShipDepCoding,cShipPersonCoding,cExpCoding,dShipSdate,dShipDate,mMoney,
cDocRequire,cState,bShipSelect,bCreate,iSaleCID,cShipCusCoding,null,bSOSubmit,
iADFlag,cADPerson,iADRole,bNote,null from inserted where bOutStore=1
end
--编辑时修改
else if exists(select 0 from Deleted) and exists(select 0 from Inserted)
begin
update a set a.iMeCoding=b.iMeCoding,a.cInTranCode=cShipCode,a.dMakeDate=b.dMakeDate,
a.cInTranOPCode=cShipOPCode,a.cITDepCoding=cShipDepCoding,a.cITPersonCoding=cShipPersonCoding,
a.cInSaleCNCoding=cExpCoding,a.dInTranSDate=dShipSdate,a.dInTranDate=dShipDate,
a.mInTranMoney=mMoney,a.cITMemo=cDocRequire,a.cState=b.cState,a.bITSelect=bShipSelect,
a.bITCreate=bCreate,a.iITCidNum=iSaleCID,a.cITCusCoding=cShipCusCoding,a.bSubmit=bSOSubmit,
a.iADFlag=b.iADFlag,a.cADPerson=b.cADPerson,a.iADRole=b.iADRole,a.bNote=b.bNote
from bd_intranout a,inserted b where b.cShipCoding=a.cInTranCoding and b.bOutStore=1
end
--删除
else if exists(select 0 from Deleted) and not exists(select 0 from Inserted)
begin
delete from bd_intranout where cInTranCoding in (select cShipCoding from Deleted where bOutStore=1)
end
end
update bd_intranout set......
from bd_intranout a ,......
吧。
on bd_shipout
for insert,update,delete
as
begin
SET NOCOUNT ON --在开始加上这句话
--新增时插入end
Create Trigger ShipOut_OutStore
on bd_shipout
for insert,update,delete
as
begin
--新增时插入
if not exists(select 0 from Deleted) and exists(select 0 from Inserted)
begin
insert into bd_intranout select cShipCoding,iMeCoding,cShipCode,dMakeDate,cShipOPCode,
cShipDepCoding,cShipPersonCoding,cExpCoding,dShipSdate,dShipDate,mMoney,
cDocRequire,cState,bShipSelect,bCreate,iSaleCID,cShipCusCoding,null,bSOSubmit,
iADFlag,cADPerson,iADRole,bNote,null from inserted where bOutStore=1
end
--编辑时修改
else if exists(select 0 from Deleted) and exists(select 0 from Inserted)
begin
if exists(select 0 from bd_intranout a,inserted b where b.cShipCoding=a.cInTranCoding and b.bOutStore=1)
update a set a.iMeCoding=b.iMeCoding,a.cInTranCode=cShipCode,a.dMakeDate=b.dMakeDate,
a.cInTranOPCode=cShipOPCode,a.cITDepCoding=cShipDepCoding,a.cITPersonCoding=cShipPersonCoding,
a.cInSaleCNCoding=cExpCoding,a.dInTranSDate=dShipSdate,a.dInTranDate=dShipDate,
a.mInTranMoney=mMoney,a.cITMemo=cDocRequire,a.cState=b.cState,a.bITSelect=bShipSelect,
a.bITCreate=bCreate,a.iITCidNum=iSaleCID,a.cITCusCoding=cShipCusCoding,a.bSubmit=bSOSubmit,
a.iADFlag=b.iADFlag,a.cADPerson=b.cADPerson,a.iADRole=b.iADRole,a.bNote=b.bNote
from bd_intranout a,inserted b where b.cShipCoding=a.cInTranCoding and b.bOutStore=1
end
--删除
else if exists(select 0 from Deleted) and not exists(select 0 from Inserted)
begin
if exists(select 0 from bd_intranout a,inserted b where b.cShipCoding=a.cInTranCoding and b.bOutStore=1)
delete from bd_intranout where cInTranCoding in (select cShipCoding from Deleted where bOutStore=1)
end
end