我是新手。我有以下代码,其内部和SSID包需要太长时间才能执行。
本声明的目的是找到最好的律师(考虑到一些生产力和能力因素)并将其身份证写入临时表......但这需要时间过长。
任何建议???我甚至试过......禁用游行
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
答案 0 :(得分:0)
首先,触发器与性能无关。您只插入一行。
在这种插入中可能会遇到两个问题:
在SSMS中运行查询。
从命名惯例来看,我会怀疑这个联接:
FROM TB_PCRelation INNER JOIN
TB_CASES
ON TB_PCRelation.PostalCode = TB_CASES.CustomerPostalCode
对案件没有明显的限制。你很可能在一个邮政编码中有很多律师和很多案件。
然而,这只是猜测。