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

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

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

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

      2. <tfoot id='Qu2oD'></tfoot>
      3. 零 SQL 死锁设计 - 任何编码模式?

        Zero SQL deadlock by design - any coding patterns?(零 SQL 死锁设计 - 任何编码模式?)
        • <i id='qVl2n'><tr id='qVl2n'><dt id='qVl2n'><q id='qVl2n'><span id='qVl2n'><b id='qVl2n'><form id='qVl2n'><ins id='qVl2n'></ins><ul id='qVl2n'></ul><sub id='qVl2n'></sub></form><legend id='qVl2n'></legend><bdo id='qVl2n'><pre id='qVl2n'><center id='qVl2n'></center></pre></bdo></b><th id='qVl2n'></th></span></q></dt></tr></i><div id='qVl2n'><tfoot id='qVl2n'></tfoot><dl id='qVl2n'><fieldset id='qVl2n'></fieldset></dl></div>
            <bdo id='qVl2n'></bdo><ul id='qVl2n'></ul>

                    <tbody id='qVl2n'></tbody>
                  <tfoot id='qVl2n'></tfoot>

                  <small id='qVl2n'></small><noframes id='qVl2n'>

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

                  本文介绍了零 SQL 死锁设计 - 任何编码模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在运行在 MS SQL Server 2005 之上的 .NET 2.0 web 应用程序上遇到了非常罕见但令人讨厌的 SQL 死锁.过去,我们一直以非常经验的方式处理 SQL 死锁 - 基本上是调整查询,直到它起作用了.

                  然而,我发现这种方法非常不令人满意:耗时且不可靠.我更愿意遵循确定性查询模式,以确保设计不会遇到 SQL 死锁 - 永远.

                  例如,在 C# 多线程编程中,一个简单的设计规则,例如必须按照它们的字典顺序获取锁,以确保不会永远发生死锁.>

                  是否有任何 SQL 编码模式可以保证防死锁?

                  解决方案

                  编写防死锁代码真的很难.即使您以相同的顺序访问表,您仍然可能会遇到死锁 [1].我在我的博客上写了 一篇博文,其中详细阐述了一些方法,可以帮助您避免并解决死锁情况.

                  如果您想确保两个语句/事务永远不会死锁,您可以通过使用 sp_lock 系统存储过程观察每个语句消耗哪些锁来实现它.为此,您必须非常快,或者使用带有锁定提示的打开事务.

                  <小时>

                  注意事项:

                  1. 任何一次需要多个锁的 SELECT 语句都可能因智能设计的事务而死锁,该事务以相反的顺序获取锁.

                  I am encountering very infrequent yet annoying SQL deadlocks on a .NET 2.0 webapp running on top of MS SQL Server 2005. In the past, we have been dealing with the SQL deadlocks in the very empirical way - basically tweaking the queries until it work.

                  Yet, I found this approach very unsatisfactory: time consuming and unreliable. I would highly prefer to follow deterministic query patterns that would ensure by design that no SQL deadlock will be encountered - ever.

                  For example, in C# multithreaded programming, a simple design rule such as the locks must be taken following their lexicographical order ensures that no deadlock will ever happen.

                  Are there any SQL coding patterns guaranteed to be deadlock-proof?

                  解决方案

                  Writing deadlock-proof code is really hard. Even when you access the tables in the same order you may still get deadlocks [1]. I wrote a post on my blog that elaborates through some approaches that will help you avoid and resolve deadlock situations.

                  If you want to ensure two statements/transactions will never deadlock you may be able to achieve it by observing which locks each statement consumes using the sp_lock system stored procedure. To do this you have to either be very fast or use an open transaction with a holdlock hint.


                  Notes:

                  1. Any SELECT statement that needs more than one lock at once can deadlock against an intelligently designed transaction which grabs the locks in reverse order.

                  这篇关于零 SQL 死锁设计 - 任何编码模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32)(超出最大存储过程、函数、触发器或视图嵌套级别(限制 32))
                  How to View Oracle Stored Procedure using SQLPlus?(如何使用 SQLPlus 查看 Oracle 存储过程?)
                  How to debug stored procedure in VS 2015?(如何在 VS 2015 中调试存储过程?)
                  Set the variable result, from query(设置变量结果,来自查询)
                  What is dynamic SQL?(什么是动态 SQL?)
                  Mysql - How to quit/exit from stored procedure(Mysql - 如何退出/退出存储过程)
                1. <tfoot id='VutLL'></tfoot>
                  <i id='VutLL'><tr id='VutLL'><dt id='VutLL'><q id='VutLL'><span id='VutLL'><b id='VutLL'><form id='VutLL'><ins id='VutLL'></ins><ul id='VutLL'></ul><sub id='VutLL'></sub></form><legend id='VutLL'></legend><bdo id='VutLL'><pre id='VutLL'><center id='VutLL'></center></pre></bdo></b><th id='VutLL'></th></span></q></dt></tr></i><div id='VutLL'><tfoot id='VutLL'></tfoot><dl id='VutLL'><fieldset id='VutLL'></fieldset></dl></div>

                      <small id='VutLL'></small><noframes id='VutLL'>

                        <tbody id='VutLL'></tbody>

                          • <bdo id='VutLL'></bdo><ul id='VutLL'></ul>
                            <legend id='VutLL'><style id='VutLL'><dir id='VutLL'><q id='VutLL'></q></dir></style></legend>