<tfoot id='sMsZ1'></tfoot>

    1. <small id='sMsZ1'></small><noframes id='sMsZ1'>

          <bdo id='sMsZ1'></bdo><ul id='sMsZ1'></ul>
        <i id='sMsZ1'><tr id='sMsZ1'><dt id='sMsZ1'><q id='sMsZ1'><span id='sMsZ1'><b id='sMsZ1'><form id='sMsZ1'><ins id='sMsZ1'></ins><ul id='sMsZ1'></ul><sub id='sMsZ1'></sub></form><legend id='sMsZ1'></legend><bdo id='sMsZ1'><pre id='sMsZ1'><center id='sMsZ1'></center></pre></bdo></b><th id='sMsZ1'></th></span></q></dt></tr></i><div id='sMsZ1'><tfoot id='sMsZ1'></tfoot><dl id='sMsZ1'><fieldset id='sMsZ1'></fieldset></dl></div>
        <legend id='sMsZ1'><style id='sMsZ1'><dir id='sMsZ1'><q id='sMsZ1'></q></dir></style></legend>

        如何在 SQL Server Management Studio 中查看查询历史记录

        How to see query history in SQL Server Management Studio(如何在 SQL Server Management Studio 中查看查询历史记录)

        <legend id='E1GYO'><style id='E1GYO'><dir id='E1GYO'><q id='E1GYO'></q></dir></style></legend>

        <tfoot id='E1GYO'></tfoot>

          <bdo id='E1GYO'></bdo><ul id='E1GYO'></ul>

              <i id='E1GYO'><tr id='E1GYO'><dt id='E1GYO'><q id='E1GYO'><span id='E1GYO'><b id='E1GYO'><form id='E1GYO'><ins id='E1GYO'></ins><ul id='E1GYO'></ul><sub id='E1GYO'></sub></form><legend id='E1GYO'></legend><bdo id='E1GYO'><pre id='E1GYO'><center id='E1GYO'></center></pre></bdo></b><th id='E1GYO'></th></span></q></dt></tr></i><div id='E1GYO'><tfoot id='E1GYO'></tfoot><dl id='E1GYO'><fieldset id='E1GYO'></fieldset></dl></div>
                <tbody id='E1GYO'></tbody>
            • <small id='E1GYO'></small><noframes id='E1GYO'>

                1. 本文介绍了如何在 SQL Server Management Studio 中查看查询历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  查询历史是否存储在某些日志文件中?如果是,你能告诉我如何找到他们的位置吗?如果没有,你能给我一些关于如何看到它的建议吗?

                  Is the query history stored in some log files? If yes, can you tell me how to find their location? If not, can you give me any advice on how to see it?

                  推荐答案

                  [自从 这个问题 可能会作为重复问题关闭.]

                  [Since this question will likely be closed as a duplicate.]

                  如果 SQL Server 没有重新启动(并且计划没有被驱逐等),您可能能够在计划缓存中找到查询.

                  If SQL Server hasn't been restarted (and the plan hasn't been evicted, etc.), you may be able to find the query in the plan cache.

                  SELECT t.[text]
                  FROM sys.dm_exec_cached_plans AS p
                  CROSS APPLY sys.dm_exec_sql_text(p.plan_handle) AS t
                  WHERE t.[text] LIKE N'%something unique about your query%';
                  

                  如果您因为 Management Studio 崩溃而丢失了文件,您可以在此处找到恢复文件:

                  If you lost the file because Management Studio crashed, you might be able to find recovery files here:

                  C:Users<you>DocumentsSQL Server Management StudioBackup Files
                  

                  否则,您将需要使用其他东西来帮助您保存查询历史记录,例如 Ed 中提到的 SSMS 工具包Harper 的回答 - 尽管它在 SQL Server 2012+ 中不是免费的.或者,您可以设置一些基于登录名或主机名过滤的轻量级跟踪(但请为此使用服务器端跟踪,而不是 Profiler).

                  Otherwise you'll need to use something else going forward to help you save your query history, like SSMS Tools Pack as mentioned in Ed Harper's answer - though it isn't free in SQL Server 2012+. Or you can set up some lightweight tracing filtered on your login or host name (but please use a server-side trace, not Profiler, for this).

                  正如@Nenad-Zivkovic 所评论的,加入sys.dm_exec_query_stats 并按last_execution_time 排序可能会有所帮助:

                  As @Nenad-Zivkovic commented, it might be helpful to join on sys.dm_exec_query_stats and order by last_execution_time:

                  SELECT t.[text], s.last_execution_time
                  FROM sys.dm_exec_cached_plans AS p
                  INNER JOIN sys.dm_exec_query_stats AS s
                     ON p.plan_handle = s.plan_handle
                  CROSS APPLY sys.dm_exec_sql_text(p.plan_handle) AS t
                  WHERE t.[text] LIKE N'%something unique about your query%'
                  ORDER BY s.last_execution_time DESC;
                  

                  这篇关于如何在 SQL Server Management Studio 中查看查询历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Select n random rows from SQL Server table(从 SQL Server 表中随机选择 n 行)
                  SQL query to select dates between two dates(用于选择两个日期之间的日期的 SQL 查询)
                  How can I delete using INNER JOIN with SQL Server?(如何在 SQL Server 中使用 INNER JOIN 进行删除?)
                  Table Naming Dilemma: Singular vs. Plural Names(表命名困境:单数与复数名称)
                  INSERT statement conflicted with the FOREIGN KEY constraint - SQL Server(INSERT 语句与 FOREIGN KEY 约束冲突 - SQL Server)
                  Optimal way to concatenate/aggregate strings(连接/聚合字符串的最佳方式)
                  <tfoot id='zLgOi'></tfoot>

                      <tbody id='zLgOi'></tbody>
                    <i id='zLgOi'><tr id='zLgOi'><dt id='zLgOi'><q id='zLgOi'><span id='zLgOi'><b id='zLgOi'><form id='zLgOi'><ins id='zLgOi'></ins><ul id='zLgOi'></ul><sub id='zLgOi'></sub></form><legend id='zLgOi'></legend><bdo id='zLgOi'><pre id='zLgOi'><center id='zLgOi'></center></pre></bdo></b><th id='zLgOi'></th></span></q></dt></tr></i><div id='zLgOi'><tfoot id='zLgOi'></tfoot><dl id='zLgOi'><fieldset id='zLgOi'></fieldset></dl></div>
                      1. <small id='zLgOi'></small><noframes id='zLgOi'>

                          <bdo id='zLgOi'></bdo><ul id='zLgOi'></ul>

                        • <legend id='zLgOi'><style id='zLgOi'><dir id='zLgOi'><q id='zLgOi'></q></dir></style></legend>