提高视图的性能

时间:2014-07-16 14:58:25

标签: sql sql-server

我想提高视图All_Risks的效果,任何人都可以帮我这样做吗?

构建视图的select语句如下

SELECT     
   dbo.Risks_RiskDataNew.RiskID, dbo.Risks_RiskDataNew.HRASnapshotId, 
   dbo.Risks_RiskDataNew.RiskDate, dbo.Risks_RiskDataNew.RiskTypeDescription, 
   dbo.Risks_RiskDataNew.AgillicUserId, dbo.Risks_RiskDataNew.SequenceNo, 
   dbo.Risks_RiskDataNew.RiskValue, dbo.Risks_RiskDataNew.RiskLevelDescription, 
   dbo.BE_RISKTYPE.RiskName, dbo.BE_RISKTYPE.RiskTypeCatagory, 
   dbo.Risks_RiskDataNew.OrganisationID
FROM         
   dbo.Risks_RiskDataNew 
INNER JOIN
   dbo.BE_RISKTYPE ON dbo.Risks_RiskDataNew.RiskTypeDescription = dbo.BE_RISKTYPE.RiskTypeDescription AND EXISTS
                          (SELECT 1 AS Expr1
                           FROM dbo.BE_CompanyInfo
                           WHERE (dbo.Risks_RiskDataNew.OrganisationID = OrganisationID))

有人建议我将其引用Risk_RiskDataNew的视图中的代码带入视图All_Risks

这是视图dbo.Risks_RiskDataNew

中的select语句
SELECT     
   BE_Risks_Sequenced_1.RiskID, BE_Risks_Sequenced_1.HRASnapshotId, 
   BE_Risks_Sequenced_1.RiskDate, BE_Risks_Sequenced_1.RiskTypeDescription, 
   BE_Risks_Sequenced_1.AgillicUserId, BE_Risks_Sequenced_1.SequenceNo, 
   BE_Risks_Sequenced_1.RiskValue, BE_Risks_Sequenced_1.RiskLevelDescription, 
   BE_Risks_Sequenced_1.OrganisationID
FROM         
   dbo.BE_Risks_Sequenced 
INNER JOIN
   dbo.BE_Risks_Sequenced AS BE_Risks_Sequenced_1 ON dbo.BE_Risks_Sequenced.RiskTypeDescription = BE_Risks_Sequenced_1.RiskTypeDescription 
                                                  AND dbo.BE_Risks_Sequenced.AgillicUserId = BE_Risks_Sequenced_1.AgillicUserId 
                                                  AND dbo.BE_Risks_Sequenced.SequenceNo = BE_Risks_Sequenced_1.SequenceNo + 1
WHERE     
   (dbo.BE_Risks_Sequenced.RiskValue = 1) 
   AND (dbo.BE_Risks_Sequenced.RiskLevelDescription NOT LIKE BE_Risks_Sequenced_1.RiskLevelDescription)

UNION ALL

SELECT     
    RiskID, HRASnapshotId, RiskDate, RiskTypeDescription, AgillicUserId, 
    SequenceNo, RiskValue, RiskLevelDescription, OrganisationID
FROM
    dbo.BE_Risks_Sequenced
WHERE     
    (SequenceNo = 1) AND (RiskValue > 1)

0 个答案:

没有答案