0

我是新来的。我有以下代码,其中内部和 SSID 包执行时间太长。

该声明旨在找到最好的律师(考虑到一些生产力和能力因素)并将其 ID 写入临时表......但它需要太长时间。

有什么建议么???我什至尝试过...禁用触发器

ALTER TABLE TB_TEMPLawyer DISABLE TRIGGER ALL
ALTER TABLE TB_LAWYERS     DISABLE TRIGGER ALL
ALTER TABLE  TB_PCRelation  DISABLE TRIGGER ALL
ALTER TABLE  TB_CASES       DISABLE TRIGGER ALL
ALTER TABLE  TB_TEMPaccount  DISABLE TRIGGER ALL

INSERT INTO TB_TEMPLawyer
                      (LawyerAutoIDTEMP)
SELECT     TOP (1) TB_LAWYERS.LawyerAutoID
FROM         TB_PCRelation INNER JOIN
                      TB_CASES ON TB_PCRelation.PostalCode = TB_CASES.CustomerPostalCode INNER JOIN
                      TB_LAWYERS ON TB_PCRelation.PCLawyerID = TB_LAWYERS.LawyerID INNER JOIN
                      TB_TEMPaccount ON TB_CASES.Account = TB_TEMPaccount.TempAccount
WHERE     (TB_CASES.LASYstatus = '2') AND (TB_CASES.LawyerID = 'NONE') AND (TB_LAWYERS.Activity = 'ACTIVE') AND 
                      (TB_LAWYERS.Relation_Type = 'EXTERNAL') AND (TB_CASES.TotalMLUSBBexposure BETWEEN TB_LAWYERS.MINAmount AND 
                      TB_LAWYERS.MAXamount) AND (TB_LAWYERS.CaseLimitMONTHLY >= TB_LAWYERS.CaseLimitMONTHLYactual) AND 
                      (TB_LAWYERS.CaseLimitDAILY >= TB_LAWYERS.CaseLimitDAILYactual) AND (TB_LAWYERS.Productivity <> '0')
ORDER BY TB_LAWYERS.Productivity DESC




ALTER TABLE TB_TEMPLawyer ENABLE TRIGGER ALL 
ALTER TABLE TB_LAWYERS     ENABLE TRIGGER ALL
ALTER TABLE  TB_PCRelation  ENABLE TRIGGER ALL
ALTER TABLE  TB_CASES       ENABLE TRIGGER ALL
ALTER TABLE  TB_TEMPaccount  ENABLE TRIGGER ALL
4

1 回答 1

0

首先,触发器与性能无关。您只插入一行。

在这种插入中可能会遇到两个问题:

  1. 目标表可能由于某种原因被锁定。我怀疑这是问题所在。
  2. 查询需要很长时间。

在 SSMS 中运行查询。

从命名约定来看,我会怀疑这个加入:

FROM TB_PCRelation INNER JOIN 
     TB_CASES
     ON TB_PCRelation.PostalCode = TB_CASES.CustomerPostalCode

对案件没有明显的限制。您很可能在一个邮政编码中有很多律师和很多案件。

然而,这只是猜测。

于 2012-05-15T13:41:58.983 回答