Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Heap storage has nothing to do with <a href="http://en.wikipedia.org/wiki/Heap_%28data_structure%29" rel="noreferrer">these heaps</a>.</p> <p>Heap just means records themselves are not ordered (i. e. not linked to one another).</p> <p>When you insert a record, it just gets inserted into the free space the database finds.</p> <h3>Updating a row in a heap based table does not affect other records (though it affects secondary indexes)</h3> <p>If you create a secondary index on a <code>HEAP</code> table, the <code>RID</code> (a kind of a physical pointer to the storage space) is used as a row pointer.</p> <p>Clustered index means that the records are part of a <code>B-Tree</code>. When you insert a record, the <code>B-Tree</code> needs to be relinked.</p> <h3>Updating a row in a clustered table causes relinking of the B-Tree, i. e. updating internal pointers in other records.</h3> <p>If you create a secondary index on a clustered table, the value of the clustered index key is used as a row pointer.</p> <p>This means a clustered index should be unique. If a clustered index is not unique, a special hidden column called <code>uniquifier</code> is appended to the index key that makes if unique (and larger in size).</p> <p>It is also worth noting that creating a secondary index on a column makes the values or the clustered index's key to be the part of the secondayry index's key.</p> <h3>By creating an index on a clustered table, you in fact always get a composite index</h3> <pre><code>CREATE UNIQUE CLUSTERED INDEX CX_mytable_1234 (col1, col2, col3, col4) CREATE INDEX IX_mytable_5678 (col5, col6, col7, col8) </code></pre> <p>Index <code>IX_mytable_5678</code> is in fact an index on the following columns:</p> <pre><code>col5 col6 col7 col8 col1 col2 col3 col4 </code></pre> <p>This has one more side effect:</p> <h3>A <code>DESC</code> condition in a single-column index on a clustered table makes sense in <code>SQL Server</code></h3> <p>This index:</p> <pre><code>CREATE INDEX IX_mytable ON mytable (col1) </code></pre> <p>can be used in a query like this:</p> <pre><code>SELECT TOP 100 * FROM mytable ORDER BY col1, id </code></pre> <p>, while this one:</p> <pre><code>CREATE INDEX IX_mytable ON mytable (col1 DESC) </code></pre> <p>can be used in a query like this:</p> <pre><code>SELECT TOP 100 * FROM mytable ORDER BY col1, id DESC </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload