提高查询的性能

时间:2013-05-20 15:05:02

标签: tsql sql-server-2008-r2

我有以下sql查询表现不好:

SELECT 
    Count(ExtCardID) as CardCount 
from 
    CardIDs CARDS with (NoLock)
inner join 
    (select CustomerPK 
     from GroupMembership with (NoLock)
     where CustomerGroupID = 14 and Deleted = 0) as GM on GM.CustomerPK = CARDS.CustomerPK

上述联接中的以下Select部分返回了800万条记录:

select 
    CustomerPK from GroupMembership with (NoLock)
where 
    CustomerGroupID = 14 and Deleted = 0

有没有更好的方法来编写上面的SQL代码?请指教。

1 个答案:

答案 0 :(得分:0)

你试过LINQ吗?

LINQ非常好而不是直接查询!

Great Article