exec sp_executesql 执行的语句很慢,直接执行里面的sql很快这是为啥 返回

求助
2 1167

慢:

exec sp_executesql N'SELECT * FROM (SELECT  [c].[BookCommentsID] AS [BookCommentsID] , [c].[BookID] AS [BookID] , [c].[BookRating] AS [BookRating] , [c].[BookComments] AS [BookComments] , [c].[BookCommentsStatus] AS [BookCommentsStatus] , [c].[BookCommentsByUserID] AS [BookCommentsByUserID] , [c].[BookCommentsDate] AS [BookCommentsDate] , [c].[ReplyCount] AS [ReplyCount] , [c].[PraiseCount] AS [PraiseCount] , [c].[BCStatus] AS [BCStatus] , [c].[IsFine] AS [IsFine] , [c].[IsTop] AS [IsTop] , [c].[IsAudit] AS [IsAudit] , [b].[BookTitle] AS [BookName] ,ROW_NUMBER() OVER(ORDER BY [c].[BookCommentsDate] DESC) AS RowIndex  FROM [BookComments] c Left JOIN Book b ON ( [c].[BookID] = [b].[BookID] )   WHERE ( [c].[BCStatus] = @BCStatus0 )) T WHERE RowIndex BETWEEN 1 AND 50',N'@BCStatus0 int',@BCStatus0=1

快:

SELECT * FROM (SELECT  [c].[BookCommentsID] AS [BookCommentsID] , [c].[BookID] AS [BookID] , [c].[BookRating] AS [BookRating] , [c].[BookComments] AS [BookComments] , [c].[BookCommentsStatus] AS [BookCommentsStatus] , [c].[BookCommentsByUserID] AS [BookCommentsByUserID] , [c].[BookCommentsDate] AS [BookCommentsDate] , [c].[ReplyCount] AS [ReplyCount] , [c].[PraiseCount] AS [PraiseCount] , [c].[BCStatus] AS [BCStatus] , [c].[IsFine] AS [IsFine] , [c].[IsTop] AS [IsTop] , [c].[IsAudit] AS [IsAudit] , [b].[BookTitle] AS [BookName] ,ROW_NUMBER() OVER(ORDER BY [c].[BookCommentsDate] DESC) AS RowIndex  FROM [BookComments] c Left JOIN Book b ON ( [c].[BookID] = [b].[BookID] )   WHERE ( [c].[BCStatus] = 1 )) T WHERE RowIndex BETWEEN 1 AND 50


热忱回答2

  • 最好可以支持指定用什么执行方式,有时候不希望用exec sp_executesql这种来执行。

    0 回复
  • .NET执行SQL只能用 exec sp_executesql  这是ADO底层的调用方式 ,一般情况下这种方式会比直接执行SQL要快,如果慢你就要对你的库找原因了。

    0 回复

版块

学习文档

最新会员

发布达人

回贴达人