set @BDate=getdate() --下面这句速度很慢,但去掉WorkReg表的触发器则正常 if not exists(select iId from WorkReg where PlanId=@PlanId and tiId=@tiId and StepId=@StepId and StationId=@Station1 and iEmplId=@iEmp1 and StationGp=@StationGp1 and RegDate=@Date1 and TmpStepAssId=@TmpStepAssId) begin set @EDate=getdate() insert into aCost(StepNo,begindate,enddate,costm) values (5,@BDate,@EDate,datediff(ms,@BDate,@EDate)) set @BDate=@EDate --插入数据至WorkReg表 select @iId=IsNull(max(iId)+1,1) from WorkReg insert into WorkReg(iId, PlanId, tiId, OrganId, ProdId, StepId, StationId, StationGp,iEmplId, Num, RegDate,PlanProdId,EmpId, WorkPrice,QuoPercent,AllQuoPercent,WorkTime,TmpStepAssId,IsTempTask, StepName,TechOrderId,StationName,SemiName,WorkNum, PlanNo,OrganCode,SalaKind,IsReversePoint,cEmpCode,cEmplN, SpecCode,DetailCode,ProdCode,ProdName,Factor,AlreadyReverse) values(@iId,@PlanId,@tiId,@OrganId,@ProdId,@StepId,@Station1,@StationGp1, @iEmp1,@Num1,@Date1,@PlanProdId,@IID1,@WorkPrice,@QuoPercent1,@AQuoPcent1, @WorkTime,@TmpStepAssId,@IsTempTask,@StepName,@TechOrderId,@StationN1,@SemiName,@WorkNum, @PlanNo,@OrganCode,@SalaKind,@IsReversePoint,@cEmpCode1,@cEmplN1,@SpecCode, @DetailCode,@ProdCode,@DetailName,@Factor,@AlreadyReverse) end else update WorkReg set Num=@Num1,QuoPercent=@QuoPercent1,AllQuoPercent=@AQuoPcent1,Factor=@Factor where PlanId=@PlanId and tiId=@tiId and StepId=@StepId and StationId=@Station1 and iEmplId=@iEmp1 and StationGp=@StationGp1 and RegDate=@Date1 and TmpStepAssId=@TmpStepAssId
是SQL 2000还是更高的版本?B表有多少条记录?
事实上,你在A表的语句的执行触发了B表的触发器的执行。 看下你的结构就清楚了if not exists( begin insert WorkReg-----可能触发B表的触发器 end else update ---也会触发B表的触发器所以你的语句肯定是触发了B表的触发器
呜呜
B表有两个触发器,insert update delete中两个,那你插入和跟新操作肯定会触发其中一个啊~~
--下面这句速度很慢,但去掉WorkReg表的触发器则正常
if not exists(select iId from WorkReg where PlanId=@PlanId and tiId=@tiId and
StepId=@StepId and StationId=@Station1 and iEmplId=@iEmp1 and
StationGp=@StationGp1 and RegDate=@Date1 and TmpStepAssId=@TmpStepAssId)
begin
set @EDate=getdate()
insert into aCost(StepNo,begindate,enddate,costm) values (5,@BDate,@EDate,datediff(ms,@BDate,@EDate))
set @BDate=@EDate
--插入数据至WorkReg表
select @iId=IsNull(max(iId)+1,1) from WorkReg
insert into WorkReg(iId, PlanId, tiId, OrganId, ProdId, StepId, StationId,
StationGp,iEmplId, Num, RegDate,PlanProdId,EmpId,
WorkPrice,QuoPercent,AllQuoPercent,WorkTime,TmpStepAssId,IsTempTask,
StepName,TechOrderId,StationName,SemiName,WorkNum,
PlanNo,OrganCode,SalaKind,IsReversePoint,cEmpCode,cEmplN,
SpecCode,DetailCode,ProdCode,ProdName,Factor,AlreadyReverse)
values(@iId,@PlanId,@tiId,@OrganId,@ProdId,@StepId,@Station1,@StationGp1,
@iEmp1,@Num1,@Date1,@PlanProdId,@IID1,@WorkPrice,@QuoPercent1,@AQuoPcent1,
@WorkTime,@TmpStepAssId,@IsTempTask,@StepName,@TechOrderId,@StationN1,@SemiName,@WorkNum,
@PlanNo,@OrganCode,@SalaKind,@IsReversePoint,@cEmpCode1,@cEmplN1,@SpecCode,
@DetailCode,@ProdCode,@DetailName,@Factor,@AlreadyReverse)
end
else
update WorkReg set Num=@Num1,QuoPercent=@QuoPercent1,AllQuoPercent=@AQuoPcent1,Factor=@Factor
where PlanId=@PlanId and tiId=@tiId and
StepId=@StepId and StationId=@Station1 and iEmplId=@iEmp1 and
StationGp=@StationGp1 and RegDate=@Date1 and TmpStepAssId=@TmpStepAssId
看下你的结构就清楚了if not exists(
begin
insert WorkReg-----可能触发B表的触发器 end
else
update ---也会触发B表的触发器所以你的语句肯定是触发了B表的触发器