在 SQL Server 中获取动态 SQL 的查询/执行计划
可能的重复:
如何获取查询执行计划?
我该如何获取查看 SQL Server 2005 中执行的动态 sql 的执行计划?我无法在数据库所在的计算机上保存任何文件。这是一个小例子:
declare @sqlcmd nvarchar(1000)
declare @param1 nvarchar(14)
set @param1 = '11111111%'
set @sqlcmd = 'SELECT * FROM myTable WHERE customer_id LIKE @customer_id'
EXECUTE sp_executesql @sqlcmd, N'@customer_id nvarchar(14)', @customer_id = @param1
所以我想看看实际用于 SELECT 查询的执行计划。
Possible Duplicate:
How do I obtain a Query Execution Plan?
how can I see the execution plan in SQL Server 2005 for a dynamic sql that is executed? I cannot save any files on the computer where the database resides. Here's a small example:
declare @sqlcmd nvarchar(1000)
declare @param1 nvarchar(14)
set @param1 = '11111111%'
set @sqlcmd = 'SELECT * FROM myTable WHERE customer_id LIKE @customer_id'
EXECUTE sp_executesql @sqlcmd, N'@customer_id nvarchar(14)', @customer_id = @param1
So I would like to see the execution plan that actually is used for SELECT query.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需在 SQL Server Management Studio 中按 ctrl + m 即可激活“包括实际执行计划”。这将显示真实的执行计划,就像任何普通查询一样。
Just press ctrl + m in SQL Server Management Studio to activate "Include Actual Execution Plan". This will show the real execution plan just as with any ordinary query.
您可以使用探查器来捕获执行计划。然后,您可以使用 SQL Sentry 的 Plan Explorer (http://www.sqlsentry.com/plan-explorer/sql-server-query-view.asp) 等工具来查看/分解捕获的查询计划。
You can use profiler to capture the execution plans. You can then use something like SQL Sentry's Plan Explorer (http://www.sqlsentry.com/plan-explorer/sql-server-query-view.asp) to be able to view/break down the captured query plans.