MSSQL选择查询优化

时间:2014-07-16 08:59:27

标签: sql sql-server

下面的选择查询是否可以进行任何优化?

    SELECT 
    AwardAction.strActionName, AwardType.strAwardName, 
    Award.strStudentId,Award.iCount
    FROM
    [dbo].[Awards] Award, [dbo].[AwardAction] AwardAction,
    [dbo].[AwardTypes] AwardType
    WHERE
    AwardType.ApplicationId=@ApplicationId and 
    Award.ID=@ID and 
    AwardAction.Action=Award.Action and 
    AwardType.Type=Award.Type

表格的设计是这样的

enter image description here

抱歉,我无法将问题转移到codereview,因为它已有答案

1 个答案:

答案 0 :(得分:1)

您最好编写显式连接:

SELECT 
AwardAction.strActionName, AwardType.strAwardName, 
Award.strStudentId,Award.iCount
FROM
[dbo].[Awards] Award
inner join [dbo].[AwardAction] AwardAction on AwardAction.Action=Award.Action
inner join [dbo].[AwardTypes] AwardType on AwardType.Type=Award.Type
WHERE
AwardType.ApplicationId=@ApplicationId and 
Award.ID=@ID

要优化查询的执行,您必须在行AwardType.ApplicationId,Award.Type和Award.Action上定义索引。