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

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

    • <bdo id='D54In'></bdo><ul id='D54In'></ul>
    1. <tfoot id='D54In'></tfoot>
      <i id='D54In'><tr id='D54In'><dt id='D54In'><q id='D54In'><span id='D54In'><b id='D54In'><form id='D54In'><ins id='D54In'></ins><ul id='D54In'></ul><sub id='D54In'></sub></form><legend id='D54In'></legend><bdo id='D54In'><pre id='D54In'><center id='D54In'></center></pre></bdo></b><th id='D54In'></th></span></q></dt></tr></i><div id='D54In'><tfoot id='D54In'></tfoot><dl id='D54In'><fieldset id='D54In'></fieldset></dl></div>
    2. SQL Server - 何时使用聚集索引与非聚集索引?

      时间:2023-10-25

        <tbody id='EZOKH'></tbody>

          <tfoot id='EZOKH'></tfoot>

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

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

                本文介绍了SQL Server - 何时使用聚集索引与非聚集索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我知道聚集索引和非聚集索引之间的主要区别,并且了解它们的实际工作方式.我了解聚簇和非聚簇索引如何提高读取性能.但我不确定的一件事是,我会选择一个而不是另一个的原因是什么.

                例如:如果一张表没有聚集索引,是否应该创建一个非聚集索引,这样做有什么好处

                解决方案

                我只想说一句警告:请非常小心选择您的聚集索引!每个常规"数据表都应该有一个聚集索引,因为拥有一个聚集索引确实会加速很多操作——是的,加速,甚至插入和删除!但前提是您选择了好的聚集索引.

                它是 SQL Server 数据库中复制最多的数据结构.聚簇键也将成为表中每个非聚簇索引的一部分.

                在选择聚类键时应该格外小心 - 它应该是:

                • (理想的 4 个字节)

                • unique(毕竟它是行指针".如果你不让它独一无二,SQL Server 会在后台为你做,花费你几个字节每个条目乘以您拥有的行数和非聚集索引的数量 - 这可能非常昂贵!)

                • 静态(永远不要改变 - 如果可能的话)

                • 理想情况下不断增加,因此您不会以可怕的索引碎片告终(GUID 与良好的集群键完全相反 - 出于这个特殊原因)

                • 它应该是不可为空的,理想情况下也是固定的宽度 - varchar(250) 是一个非常糟糕的聚类键

                在这些点之后,其他任何事情都应该是第二和第三级的重要性......

                查看 Kimberly Tripp(索引女王)关于该主题的一些博客文章 - 她在博客中写的任何内容都绝对无价 - 阅读它,消化它 - 以它为生!>

                • GUID 作为主键和/或聚类键
                • 聚集索引的争论仍在继续......
                • 不断增加的聚类键 -聚集索引的争论..........再次!
                • 磁盘空间很便宜 - 这不是点!

                I know primary differences between clustered and non clustered indexes and have an understanding of how they actually work. I understand how clustered and non-clustered indexes improve read performance. But one thing I am not sure is that what would be the reasons where I would choose one over the other.

                For example: If a table does not have a clustered index, should one create a non-clustered index and whats the benefit of doing

                解决方案

                I just want to put in a word of warning: please very carefully pick your clustered index! Every "regular" data table ought to have a clustered index, since having a clustered index does indeed speed up a lot of operations - yes, speed up, even inserts and deletes! But only if you pick a good clustered index.

                It's the most replicated data structure in your SQL Server database. The clustering key will be part of each and every non-clustered index on your table, too.

                You should use extreme care when picking a clustering key - it should be:

                • narrow (4 bytes ideal)

                • unique (it's the "row pointer" after all. If you don't make it unique SQL Server will do it for you in the background, costing you a couple of bytes for each entry times the number of rows and the number of nonclustered indices you have - this can be very costly!)

                • static (never change - if possible)

                • ideally ever-increasing so you won't end up with horrible index fragmentation (a GUID is the total opposite of a good clustering key - for that particular reason)

                • it should be non-nullable and ideally also fixed width - a varchar(250) makes a very poor clustering key

                Anything else should really be second and third level of importance behind these points ....

                See some of Kimberly Tripp's (The Queen of Indexing) blog posts on the topic - anything she has written in her blog is absolutely invaluable - read it, digest it - live by it!

                • GUIDs as PRIMARY KEYs and/or the clustering key
                • The Clustered Index Debate Continues...
                • Ever-increasing clustering key - the Clustered Index Debate..........again!
                • Disk space is cheap - that's not the point!

                这篇关于SQL Server - 何时使用聚集索引与非聚集索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:聚集索引和非聚集索引的区别 下一篇:用mysql处理非常大的数据

                相关文章

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

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

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

                    • <bdo id='MRpfL'></bdo><ul id='MRpfL'></ul>
                    <tfoot id='MRpfL'></tfoot>