小编Chr*_*n V的帖子

SQL Server 2005查询的性能

--------------------这需要4秒才能执行(有2000 000行)为什么?---------------- -----

DECLARE @AccountId INT 
DECLARE @Max INT 
DECLARE @MailingListId INT 

SET @AccountId = 6730
SET @Max = 2000
SET @MailingListId = 82924

SELECT TOP (@Max) anp_Subscriber.Id , Name, Email 
FROM anp_Subscription WITH(NOLOCK) 
  INNER JOIN anp_Subscriber WITH(NOLOCK) 
    ON anp_Subscriber.Id = anp_Subscription.SubscriberId
WHERE [MailingListId] = @MailingListId 
  AND Name LIKE '%joe%' 
  AND [AccountID] = @AccountId
Run Code Online (Sandbox Code Playgroud)

---------------------这需要<1秒才能执行(有2000 000行)---------------- -------

SELECT TOP 2000 anp_Subscriber.Id ,Name, Email 
FROM anp_Subscription WITH(NOLOCK) 
  INNER JOIN anp_Subscriber WITH(NOLOCK)
    ON anp_Subscriber.Id = anp_Subscription.SubscriberId
WHERE [MailingListId] = 82924 
  AND Name …
Run Code Online (Sandbox Code Playgroud)

sql sql-server sql-server-2005

4
推荐指数
1
解决办法
161
查看次数

标签 统计

sql ×1

sql-server ×1

sql-server-2005 ×1