<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>non clustered index &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/non-clustered-index/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Thu, 12 Jan 2017 21:08:07 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.6</generator>
	<item>
		<title>SQL Server: Avoid the use of Indexes on VARCHAR columns</title>
		<link>https://www.dbrnd.com/2017/01/sql-server-avoid-the-use-of-indexes-on-varchar-columns-clustered-non-clustered-index-size/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 12 Jan 2017 21:08:07 +0000</pubDate>
				<category><![CDATA[Database Designing]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[clustered index]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[Database Design]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[Index key size]]></category>
		<category><![CDATA[non clustered index]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4301</guid>

					<description><![CDATA[I am also adding a Database Design category for this post, because what I am feeling that you guys must know about this before designing tables or indexes. You can create Indexes on VARCHAR columns, but you should not create indexes on big size of VARCHAR Columns. Indexes also require storing data as key for [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F01%2Fsql-server-avoid-the-use-of-indexes-on-varchar-columns-clustered-non-clustered-index-size%2F&amp;linkname=SQL%20Server%3A%20Avoid%20the%20use%20of%20Indexes%20on%20VARCHAR%20columns" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F01%2Fsql-server-avoid-the-use-of-indexes-on-varchar-columns-clustered-non-clustered-index-size%2F&amp;linkname=SQL%20Server%3A%20Avoid%20the%20use%20of%20Indexes%20on%20VARCHAR%20columns" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F01%2Fsql-server-avoid-the-use-of-indexes-on-varchar-columns-clustered-non-clustered-index-size%2F&amp;linkname=SQL%20Server%3A%20Avoid%20the%20use%20of%20Indexes%20on%20VARCHAR%20columns" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F01%2Fsql-server-avoid-the-use-of-indexes-on-varchar-columns-clustered-non-clustered-index-size%2F&amp;linkname=SQL%20Server%3A%20Avoid%20the%20use%20of%20Indexes%20on%20VARCHAR%20columns" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F01%2Fsql-server-avoid-the-use-of-indexes-on-varchar-columns-clustered-non-clustered-index-size%2F&amp;linkname=SQL%20Server%3A%20Avoid%20the%20use%20of%20Indexes%20on%20VARCHAR%20columns" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F01%2Fsql-server-avoid-the-use-of-indexes-on-varchar-columns-clustered-non-clustered-index-size%2F&amp;linkname=SQL%20Server%3A%20Avoid%20the%20use%20of%20Indexes%20on%20VARCHAR%20columns" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F01%2Fsql-server-avoid-the-use-of-indexes-on-varchar-columns-clustered-non-clustered-index-size%2F&#038;title=SQL%20Server%3A%20Avoid%20the%20use%20of%20Indexes%20on%20VARCHAR%20columns" data-a2a-url="https://www.dbrnd.com/2017/01/sql-server-avoid-the-use-of-indexes-on-varchar-columns-clustered-non-clustered-index-size/" data-a2a-title="SQL Server: Avoid the use of Indexes on VARCHAR columns"></a></p><p>I am also adding a Database Design category for this post, because what I am feeling that you guys must know about this before designing tables or indexes. </p>
<p>You can create Indexes on VARCHAR columns, but you should not create indexes on big size of VARCHAR Columns. </p>
<p>Indexes also require storing data as key for accessing associated records. There is a size limitation of index key values. </p>
<blockquote><p>Before SQL Server 2016, Index key size limitation was 900 bytes for Clustered and Non-Clustered index column.<br />
SQL Server 2016 increased this limitation for Non-Clustered Index and now it is up to 1700 bytes, but for Clustered Index column it is still 900 bytes.</p></blockquote>
<p>Let me demonstrate this.</p>
<p><strong>Create a sample table with Nonclustered Index:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_TestVarcharNonClustered
(
	ID INT
	,Name VARCHAR(2000)
)
GO

CREATE NONCLUSTERED INDEX idx_tbl_TestVarcharNonClustered_Name ON tbl_TestVarcharNonClustered(Name)
GO</pre> </p>
<p><strong>You will get a below warning:</strong><br />
Because we have set Name VARCHAR(2000).</p>
<pre class="crayon-plain-tag">Warning! The maximum key length for a nonclustered index is 1700 bytes. The index 'idx_tbl_TestVarcharNonClustered_Name' has maximum length of 2000 bytes. For some combination of large values, the insert/update operation will fail.</pre> </p>
<p><strong>Try to insert 1701 bytes data:</strong></p>
<pre class="crayon-plain-tag">INSERT INTO tbl_TestVarcharNonClustered 
VALUES (1,REPLICATE('a',1701))
GO</pre> </p>
<p><strong>You will get a below error:</strong></p>
<pre class="crayon-plain-tag">Msg 1946, Level 16, State 3, Line 1
Operation failed. The index entry of length 1701 bytes for the index 'idx_tbl_TestVarcharNonClustered_Name' exceeds the maximum length of 1700 bytes for nonclustered indexes.</pre> </p>
<p><strong>You can successfully run below INSERT, because it inserts only 1700 bytes:</strong></p>
<pre class="crayon-plain-tag">INSERT INTO tbl_TestVarcharNonClustered 
VALUES (1,REPLICATE('a',1700))
GO</pre> </p>
<p><strong>Now, create a sample table with Clustered Index:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_TestVarcharClustered
(
	ID INT
	,Name VARCHAR(2000)
)
GO

CREATE CLUSTERED INDEX idx_tbl_TestVarcharClustered_Name ON tbl_TestVarcharClustered(Name)
GO</pre> </p>
<p><strong>You will get a below warning:</strong><br />
Because we have set Name VARCHAR(2000) on cluster index column.</p>
<pre class="crayon-plain-tag">Warning! The maximum key length for a clustered index is 900 bytes. The index 'idx_tbl_TestVarcharClustered_Name' has maximum length of 2000 bytes. For some combination of large values, the insert/update operation will fail.</pre> </p>
<p><strong>Try to insert a over size data like more than 900 bytes:</strong></p>
<pre class="crayon-plain-tag">INSERT INTO tbl_TestVarcharClustered 
VALUES (1,REPLICATE('a',1001))
GO</pre> </p>
<p><strong>You will get a below error:</strong></p>
<pre class="crayon-plain-tag">Msg 1946, Level 16, State 3, Line 1
Operation failed. The index entry of length 1001 bytes for the index 'idx_tbl_TestVarcharClustered_Name' exceeds the maximum length of 900 bytes for clustered indexes.</pre> </p>
<p><strong>You can successfully run below INSERT, because it inserts only 900 bytes:</strong></p>
<pre class="crayon-plain-tag">INSERT INTO tbl_TestVarcharClustered 
VALUES (1,REPLICATE('a',900))
GO</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server: Database Indexes Interview Questions and Answers (Day-1)</title>
		<link>https://www.dbrnd.com/2016/06/sql-server-database-indexes-interview-questions-and-answers-clustered-non-clustered-hash-filtered-full-text-index-day-1/</link>
					<comments>https://www.dbrnd.com/2016/06/sql-server-database-indexes-interview-questions-and-answers-clustered-non-clustered-hash-filtered-full-text-index-day-1/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Wed, 08 Jun 2016 17:45:13 +0000</pubDate>
				<category><![CDATA[SQL Server Interview]]></category>
		<category><![CDATA[answer]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[clustered index]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Filtered Index]]></category>
		<category><![CDATA[full text search index]]></category>
		<category><![CDATA[indexes]]></category>
		<category><![CDATA[interview]]></category>
		<category><![CDATA[non clustered index]]></category>
		<category><![CDATA[question]]></category>
		<category><![CDATA[spatial index]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=2944</guid>

					<description><![CDATA[What is a Clustered Index? Clustered Index stores a key value in the same data or row page. It is attached with data rows. Clustered indexes sort and store the data rows in the table or view based on their key values. For example, each and every book has attached one page number on each [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F06%2Fsql-server-database-indexes-interview-questions-and-answers-clustered-non-clustered-hash-filtered-full-text-index-day-1%2F&amp;linkname=SQL%20Server%3A%20Database%20Indexes%20Interview%20Questions%20and%20Answers%20%28Day-1%29" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F06%2Fsql-server-database-indexes-interview-questions-and-answers-clustered-non-clustered-hash-filtered-full-text-index-day-1%2F&amp;linkname=SQL%20Server%3A%20Database%20Indexes%20Interview%20Questions%20and%20Answers%20%28Day-1%29" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F06%2Fsql-server-database-indexes-interview-questions-and-answers-clustered-non-clustered-hash-filtered-full-text-index-day-1%2F&amp;linkname=SQL%20Server%3A%20Database%20Indexes%20Interview%20Questions%20and%20Answers%20%28Day-1%29" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F06%2Fsql-server-database-indexes-interview-questions-and-answers-clustered-non-clustered-hash-filtered-full-text-index-day-1%2F&amp;linkname=SQL%20Server%3A%20Database%20Indexes%20Interview%20Questions%20and%20Answers%20%28Day-1%29" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F06%2Fsql-server-database-indexes-interview-questions-and-answers-clustered-non-clustered-hash-filtered-full-text-index-day-1%2F&amp;linkname=SQL%20Server%3A%20Database%20Indexes%20Interview%20Questions%20and%20Answers%20%28Day-1%29" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F06%2Fsql-server-database-indexes-interview-questions-and-answers-clustered-non-clustered-hash-filtered-full-text-index-day-1%2F&amp;linkname=SQL%20Server%3A%20Database%20Indexes%20Interview%20Questions%20and%20Answers%20%28Day-1%29" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F06%2Fsql-server-database-indexes-interview-questions-and-answers-clustered-non-clustered-hash-filtered-full-text-index-day-1%2F&#038;title=SQL%20Server%3A%20Database%20Indexes%20Interview%20Questions%20and%20Answers%20%28Day-1%29" data-a2a-url="https://www.dbrnd.com/2016/06/sql-server-database-indexes-interview-questions-and-answers-clustered-non-clustered-hash-filtered-full-text-index-day-1/" data-a2a-title="SQL Server: Database Indexes Interview Questions and Answers (Day-1)"></a></p><p><strong>What is a Clustered Index?</strong></p>
<blockquote><p>Clustered Index stores a key value in the same data or row page. It is attached with data rows.</p>
<p>Clustered indexes sort and store the data rows in the table or view based on their key values.</p>
<p>For example, each and every book has attached one page number on each page so this called clustered index of that book.</p></blockquote>
<p><strong>How many clustered indexes there can be in one table?</strong></p>
<blockquote><p>You can create only one clustered index.</p></blockquote>
<p><strong>What is a Non-clustered Index?</strong></p>
<blockquote><p>Nonclustered indexes have a structure separate from the data rows. A nonclustered index contains the nonclustered index key values and each key value entry has a pointer to the data row that contains the key value.</p>
<p>The pointer from an index row in a nonclustered index to a data row is called a row locator. The structure of the row locator depends on whether the data pages are stored in a heap or a clustered table. For a heap, a row locator is a pointer to the row. For a clustered table, the row locator is the clustered index key.</p>
<p>You can add nonkey columns to the leaf level of the nonclustered index to by-pass existing index key limits, 900 bytes and 16 key columns, and execute fully covered, indexed, queries.</p></blockquote>
<p><strong>Can you make non-clustered indexes as unique index?</strong></p>
<blockquote><p>Yes, you can create unique non-clustered index in which no two rows can have the same value for the index key.</p></blockquote>
<p><strong>What is a Hash Index?</strong></p>
<blockquote><p>With a hash index, data is accessed through an in-memory hash table. Hash indexes consume a fixed amount of memory, which is a function of the bucket count.</p>
<p>hash indexes are used is because hash tables are extremely efficient when it comes to just looking up values. So, queries that compare for equality to a string can retrieve values very fast if they use a hash index.</p></blockquote>
<p><strong>What is the main disadvantage of the Hash Index?</strong></p>
<blockquote><p>Hash tables are not sorted data structures, and there are many types of queries which hash indexes can not even help with.</p>
<p>For instance, suppose you want to find out all of the employees who are less than 40 years old. How could you do that with a hash table index? Well, it’s not possible because a hash table is only good for looking up key value pairs – which means queries that check for equality condition.</p></blockquote>
<p><strong>What is a Unique Index?</strong></p>
<blockquote><p>A unique index ensures that the index key contains no duplicate values and therefore every row in the table or view is in some way unique.</p>
<p>Uniqueness can be a property of both clustered and nonclustered indexes.</p></blockquote>
<p><strong>Why CLUSTERED INDEX is a Special Index in the SQL Server?</strong></p>
<blockquote><p>The clustered index in any table has special uses and significance. This index is the data itself, and it will be used in every nonclustered index in the table. If you are defining a new clustered index or changing a clustered index, SQL Server will need to do IO on every nonclustered index on the table as well.</p></blockquote>
<p><strong>T-SQL Script to create a CLUSTERED INDEX.</strong></p><pre class="crayon-plain-tag">CREATE CLUSTERED INDEX Index_Name ON Schema.TableName(Column);</pre><p>
<strong>T-SQL Script to create a NONCLUSTERED INDEX.</strong></p><pre class="crayon-plain-tag">CREATE NONCLUSTERED INDEX Index_Name ON Schema.TableName(Column);</pre><p>
<strong>T-SQL Script to create a NONCLUSTERED INDEX with covered nonkey columns.</strong></p><pre class="crayon-plain-tag">CREATE NONCLUSTERED INDEX Index_Name ON Schema.TableName(Column) INCLUDE (ColumnA, ColumnB);</pre><p>
<strong>What is a Filtered Index?</strong></p>
<blockquote><p>An optimized nonclustered index, especially suited to cover queries that select from a well-defined subset of data. It uses a filter predicate to index a portion of rows in the table. A well-designed filtered index can improve query performance, reduce index maintenance costs, and reduce index storage costs compared with full-table indexes.</p></blockquote>
<p><strong>What is a Full-text Index?</strong></p>
<blockquote><p>A special type of token-based functional index that is built and maintained by the Microsoft Full-Text Engine for SQL Server. It provides efficient support for sophisticated word searches in character string data.</p></blockquote>
<p><strong>What is a Spatial Index?</strong></p>
<blockquote><p>A spatial index provides the ability to perform certain operations more efficiently on spatial objects (spatial data) in a column of the geometry data type. The spatial index reduces the number of objects on which relatively costly spatial operations need to be applied.</p></blockquote>
<p><strong>What are Covering Indexes and Covered Queries in SQL Server?</strong></p>
<blockquote><p>If all the columns requested in the select list of query, are available in the index, then the query engine doesn&#8217;t have to lookup the table again which can significantly increase the performance of the query. Since all the requested columns are available with in the index, the index is covering the query. So, the query is called a covering query and the index is a covering index.</p>
<p>A clustered index can always cover a query, if the columns in the select list are from the same table.</p></blockquote>
<p><strong>How Indexes are used by the Query Optimizer?</strong></p>
<blockquote><p>Well-designed indexes can reduce disk I/O operations and consume fewer system resources therefore improving query performance. Indexes can be helpful for a variety of queries that contain SELECT, UPDATE, DELETE, or MERGE statements.</p>
<p>When the query optimizer uses an index, it searches the index key columns, finds the storage location of the rows needed by the query and extracts the matching rows from that location. Generally, searching the index is much faster than searching the table because unlike a table, an index frequently contains very few columns per row and the rows are in sorted order.</p></blockquote>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/06/sql-server-database-indexes-interview-questions-and-answers-clustered-non-clustered-hash-filtered-full-text-index-day-1/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
	</channel>
</rss>
