• <tfoot id='y2nHm'></tfoot>

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

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

        <i id='y2nHm'><tr id='y2nHm'><dt id='y2nHm'><q id='y2nHm'><span id='y2nHm'><b id='y2nHm'><form id='y2nHm'><ins id='y2nHm'></ins><ul id='y2nHm'></ul><sub id='y2nHm'></sub></form><legend id='y2nHm'></legend><bdo id='y2nHm'><pre id='y2nHm'><center id='y2nHm'></center></pre></bdo></b><th id='y2nHm'></th></span></q></dt></tr></i><div id='y2nHm'><tfoot id='y2nHm'></tfoot><dl id='y2nHm'><fieldset id='y2nHm'></fieldset></dl></div>
      1. 确定记录是否存在的最快方法

        时间:2023-10-08

      2. <small id='lIDcx'></small><noframes id='lIDcx'>

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

                <tbody id='lIDcx'></tbody>

                  <tfoot id='lIDcx'></tfoot>
                • <legend id='lIDcx'><style id='lIDcx'><dir id='lIDcx'><q id='lIDcx'></q></dir></style></legend>
                  本文介绍了确定记录是否存在的最快方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  正如标题所暗示的......我试图找出开销最少的最快方法来确定表中是否存在记录.

                  As the title suggests... I'm trying to figure out the fastest way with the least overhead to determine if a record exists in a table or not.

                  示例查询:

                  SELECT COUNT(*) FROM products WHERE products.id = ?;
                  
                      vs
                  
                  SELECT COUNT(products.id) FROM products WHERE products.id = ?;
                  
                      vs
                  
                  SELECT products.id FROM products WHERE products.id = ?;
                  

                  ?'TB100' 交换...第一个和第二个查询将返回完全相同的结果(例如... 1 用于此对话).最后一个查询将按预期返回 'TB100',如果 id 不在表中,则不返回任何内容.

                  Say the ? is swapped with 'TB100'... both the first and second queries will return the exact same result (say... 1 for this conversation). The last query will return 'TB100' as expected, or nothing if the id is not present in the table.

                  目的是确定id是否在表中.如果不是,程序接下来将插入记录,如果是,程序将跳过它或根据本问题范围之外的其他程序逻辑执行 UPDATE 查询.

                  The purpose is to figure out if the id is in the table or not. If not, the program will next insert the record, if it is, the program will skip it or perform an UPDATE query based on other program logic outside the scope of this question.

                  哪个更快且开销更少?(这将在每次程序运行时重复数万次,并且每天运行多次).

                  Which is faster and has less overhead? (This will be repeated tens of thousands of times per program run, and will be run many times a day).

                  (通过 M$ 提供的 JDBC 驱动程序从 Java 对 M$ SQL Server 运行此查询)

                  (Running this query against M$ SQL Server from Java via the M$ provided JDBC driver)

                  推荐答案

                  SELECT TOP 1 products.id FROM products WHERE products.id = ?; 将优于您的所有建议,因为它将终止执行在它找到第一条记录之后.

                  SELECT TOP 1 products.id FROM products WHERE products.id = ?; will outperform all of your suggestions as it will terminate execution after it finds the first record.

                  这篇关于确定记录是否存在的最快方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在查询中使用 except 时出现语法错误 下一篇:在 SQL Server 中执行嵌套 case 语句逻辑的最佳方法

                  相关文章

                    <legend id='fBvXW'><style id='fBvXW'><dir id='fBvXW'><q id='fBvXW'></q></dir></style></legend><tfoot id='fBvXW'></tfoot>

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

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