<?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>clustered index &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/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>Wed, 28 Feb 2018 19:53:53 +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 Interview: Primary Key Column as Non Clustered Index, Non Primary Key Column as Clustered Index</title>
		<link>https://www.dbrnd.com/2018/03/sql-server-interview-primary-key-column-as-non-clustered-index-non-primary-key-column-as-clustered-index/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sat, 10 Mar 2018 16:16:36 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server Interview]]></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[Nonclustered Index]]></category>
		<category><![CDATA[Primary key]]></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=4236</guid>

					<description><![CDATA[In this post, I am sharing an important interview question for SQL Server Database Developer. The question is: Can we apply Non-clustered Index on Primary Key Column, Can we apply Clustered Index on Non-Primary key column? Last year we arranged a walk in interview for SQL Server Developer. I had taken around 19 f2f interviews [&#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%2F2018%2F03%2Fsql-server-interview-primary-key-column-as-non-clustered-index-non-primary-key-column-as-clustered-index%2F&amp;linkname=SQL%20Server%20Interview%3A%20Primary%20Key%20Column%20as%20Non%20Clustered%20Index%2C%20Non%20Primary%20Key%20Column%20as%20Clustered%20Index" 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%2F2018%2F03%2Fsql-server-interview-primary-key-column-as-non-clustered-index-non-primary-key-column-as-clustered-index%2F&amp;linkname=SQL%20Server%20Interview%3A%20Primary%20Key%20Column%20as%20Non%20Clustered%20Index%2C%20Non%20Primary%20Key%20Column%20as%20Clustered%20Index" 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%2F2018%2F03%2Fsql-server-interview-primary-key-column-as-non-clustered-index-non-primary-key-column-as-clustered-index%2F&amp;linkname=SQL%20Server%20Interview%3A%20Primary%20Key%20Column%20as%20Non%20Clustered%20Index%2C%20Non%20Primary%20Key%20Column%20as%20Clustered%20Index" 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%2F2018%2F03%2Fsql-server-interview-primary-key-column-as-non-clustered-index-non-primary-key-column-as-clustered-index%2F&amp;linkname=SQL%20Server%20Interview%3A%20Primary%20Key%20Column%20as%20Non%20Clustered%20Index%2C%20Non%20Primary%20Key%20Column%20as%20Clustered%20Index" 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%2F2018%2F03%2Fsql-server-interview-primary-key-column-as-non-clustered-index-non-primary-key-column-as-clustered-index%2F&amp;linkname=SQL%20Server%20Interview%3A%20Primary%20Key%20Column%20as%20Non%20Clustered%20Index%2C%20Non%20Primary%20Key%20Column%20as%20Clustered%20Index" 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%2F2018%2F03%2Fsql-server-interview-primary-key-column-as-non-clustered-index-non-primary-key-column-as-clustered-index%2F&amp;linkname=SQL%20Server%20Interview%3A%20Primary%20Key%20Column%20as%20Non%20Clustered%20Index%2C%20Non%20Primary%20Key%20Column%20as%20Clustered%20Index" 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%2F2018%2F03%2Fsql-server-interview-primary-key-column-as-non-clustered-index-non-primary-key-column-as-clustered-index%2F&#038;title=SQL%20Server%20Interview%3A%20Primary%20Key%20Column%20as%20Non%20Clustered%20Index%2C%20Non%20Primary%20Key%20Column%20as%20Clustered%20Index" data-a2a-url="https://www.dbrnd.com/2018/03/sql-server-interview-primary-key-column-as-non-clustered-index-non-primary-key-column-as-clustered-index/" data-a2a-title="SQL Server Interview: Primary Key Column as Non Clustered Index, Non Primary Key Column as Clustered Index"></a></p><p>In this post, I am sharing an important interview question for SQL Server Database Developer.</p>
<p><strong>The question is:</strong></p>
<blockquote><p><strong>Can we apply Non-clustered Index on Primary Key Column, Can we apply Clustered Index on Non-Primary key column?</strong></p></blockquote>
<blockquote><p>Last year we arranged a walk in interview for SQL Server Developer. I had taken around 19 f2f interviews and prepared list of questions for another 88 f2f interviews. </p></blockquote>
<blockquote><p>I asked this question to all 19 candidates and 16 candidates said, we cannot create a Non-clustered Index on Primary Key because Primary Key has a default Clustered Index.<br />
This is wrong, You can create Non-clustered Primary key and can apply Clustered Index on Non-Primary key column.</p></blockquote>
<p>The main reason for this confusion is, SQL Server creates default Clustered Index on the Primary Key column. </p>
<p><strong>Our answer should be like:</strong> <em>Yes, we can define Non-Clustered Primary key column and can define Clustered index on other Non-Primary Key column.</em></p>
<blockquote><p>But the best practice is to define a Primary Key as Clustered Index because Unique value + Physical Order of data returns good query performance.</p></blockquote>
<p>In most of the cases, we are joining data using our Primary Key column, but If we require our main joining on other Non-Primary column and also require records basis on that Non-Primary column data order, we should apply Clustered Index on that Non-Primary key column. </p>
<p><strong>T-SQL Script to create NonClustered Primary Key and Clustered Index Non-Primary key column:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_Students
(
	StudID INT 
	,StudName VARCHAR(20)
	,CONSTRAINT pk_tbl_Students_StudID PRIMARY KEY NONCLUSTERED (StudID)
)
GO

CREATE CLUSTERED INDEX idx_tbl_Students_StudName ON tbl_Students (StudName)
GO</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server: How to repair corrupted Clustered Index using REPAIR_REBUILD option</title>
		<link>https://www.dbrnd.com/2017/03/sql-server-how-to-repair-corrupted-clustered-index-using-repair_rebuild-option-dbcc-checkdb-dbcc-checktable/</link>
					<comments>https://www.dbrnd.com/2017/03/sql-server-how-to-repair-corrupted-clustered-index-using-repair_rebuild-option-dbcc-checkdb-dbcc-checktable/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sat, 11 Mar 2017 16:16:39 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[clustered index]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[DBCC CHECKDB]]></category>
		<category><![CDATA[DBCC CHECKTABLE]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Index corruption]]></category>
		<category><![CDATA[Rebuild Clustered Index]]></category>
		<category><![CDATA[Repair Index]]></category>
		<category><![CDATA[REPAIR_REBUILD]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Error]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tuning]]></category>
		<category><![CDATA[SQL Server Programming]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4731</guid>

					<description><![CDATA[I executed DBCC CHECKTABLE on one of my tables, and I got below error. &#8220;table &#8216;tbl_students&#8217; (ID 6589332541). Data row does not have a matching index row in the index &#8216;idx_tbl_students_id&#8217; (ID 88). Possible missing or invalid keys for the index row matching.&#8221; The above error is indicating the corruption of index &#8220;idx_tbl_students_id&#8221; so few [&#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%2F03%2Fsql-server-how-to-repair-corrupted-clustered-index-using-repair_rebuild-option-dbcc-checkdb-dbcc-checktable%2F&amp;linkname=SQL%20Server%3A%20How%20to%20repair%20corrupted%20Clustered%20Index%20using%20REPAIR_REBUILD%20option" 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%2F03%2Fsql-server-how-to-repair-corrupted-clustered-index-using-repair_rebuild-option-dbcc-checkdb-dbcc-checktable%2F&amp;linkname=SQL%20Server%3A%20How%20to%20repair%20corrupted%20Clustered%20Index%20using%20REPAIR_REBUILD%20option" 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%2F03%2Fsql-server-how-to-repair-corrupted-clustered-index-using-repair_rebuild-option-dbcc-checkdb-dbcc-checktable%2F&amp;linkname=SQL%20Server%3A%20How%20to%20repair%20corrupted%20Clustered%20Index%20using%20REPAIR_REBUILD%20option" 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%2F03%2Fsql-server-how-to-repair-corrupted-clustered-index-using-repair_rebuild-option-dbcc-checkdb-dbcc-checktable%2F&amp;linkname=SQL%20Server%3A%20How%20to%20repair%20corrupted%20Clustered%20Index%20using%20REPAIR_REBUILD%20option" 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%2F03%2Fsql-server-how-to-repair-corrupted-clustered-index-using-repair_rebuild-option-dbcc-checkdb-dbcc-checktable%2F&amp;linkname=SQL%20Server%3A%20How%20to%20repair%20corrupted%20Clustered%20Index%20using%20REPAIR_REBUILD%20option" 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%2F03%2Fsql-server-how-to-repair-corrupted-clustered-index-using-repair_rebuild-option-dbcc-checkdb-dbcc-checktable%2F&amp;linkname=SQL%20Server%3A%20How%20to%20repair%20corrupted%20Clustered%20Index%20using%20REPAIR_REBUILD%20option" 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%2F03%2Fsql-server-how-to-repair-corrupted-clustered-index-using-repair_rebuild-option-dbcc-checkdb-dbcc-checktable%2F&#038;title=SQL%20Server%3A%20How%20to%20repair%20corrupted%20Clustered%20Index%20using%20REPAIR_REBUILD%20option" data-a2a-url="https://www.dbrnd.com/2017/03/sql-server-how-to-repair-corrupted-clustered-index-using-repair_rebuild-option-dbcc-checkdb-dbcc-checktable/" data-a2a-title="SQL Server: How to repair corrupted Clustered Index using REPAIR_REBUILD option"></a></p><p>I executed DBCC CHECKTABLE on one of my tables, and I got below error.<br />
<em>&#8220;table &#8216;tbl_students&#8217; (ID 6589332541). Data row does not have a matching index row in the index &#8216;idx_tbl_students_id&#8217; (ID 88). Possible missing or invalid keys for the index row matching.&#8221;</em></p>
<blockquote><p>The above error is indicating the corruption of index &#8220;idx_tbl_students_id&#8221; so few records are missing.<br />
If your index corrupted, there are two possible solutions. One is Restore your database backup and Second is Rebuild your corrupted indexes.</p></blockquote>
<p>People are using REBUILD command for rebuilding the indexes, but in this article, I repaired the index using option REPAIR_REBUILD of DBCC. </p>
<blockquote><p>You can use the REPAIR_REBUILD option with DBCC CHECKDB and DBCC CHECKTABLE. While executing those DBCC commands, you can repair corrupted indexes. </p></blockquote>
<p>This can include quick repairs, such as repairing missing rows in non-clustered indexes, and more time-consuming repairs, such as rebuilding an index.</p>
<p>Following are example, </p>
<pre class="crayon-plain-tag">DBCC CHECKDB ('Database_Name', REPAIR_REBUILD)
DBCC CHECKTABLE ('Table_Name', REPAIR_REBUILD)</pre> </p>
<p>You can use below article and find script to rebuild all indexes of SQL Server Database:</p>
<blockquote class="wp-embedded-content" data-secret="BjywMbat3a"><p><a href="https://www.dbrnd.com/2016/10/sql-server-t-sql-script-to-rebuild-all-indexes-of-a-database-remove-index-fragmentation-require-exclusive-lock/">SQL Server: T-SQL Script to Rebuild all Indexes of a Database</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/10/sql-server-t-sql-script-to-rebuild-all-indexes-of-a-database-remove-index-fragmentation-require-exclusive-lock/embed/#?secret=BjywMbat3a" data-secret="BjywMbat3a" width="600" height="338" title="&#8220;SQL Server: T-SQL Script to Rebuild all Indexes of a Database&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2017/03/sql-server-how-to-repair-corrupted-clustered-index-using-repair_rebuild-option-dbcc-checkdb-dbcc-checktable/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server: Move your Table from one File Group to another File Group</title>
		<link>https://www.dbrnd.com/2017/02/sql-server-move-your-table-from-one-file-group-to-another-file-group-move-clustered-index/</link>
					<comments>https://www.dbrnd.com/2017/02/sql-server-move-your-table-from-one-file-group-to-another-file-group-move-clustered-index/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Fri, 10 Feb 2017 20:16:26 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[.ndf]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[clustered index]]></category>
		<category><![CDATA[Data File]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[File group]]></category>
		<category><![CDATA[move table]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Error]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tuning]]></category>
		<category><![CDATA[SQL Server Programming]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4499</guid>

					<description><![CDATA[If you are finding most top 10 steps for SQL Server Performance tuning, you could get one of the items in the list is &#8220;multiple file-groups and various data-files increases the query performance&#8221;.This is correct. You can move your fat table from master or primary data group to another custom file group. It gives you [&#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%2F02%2Fsql-server-move-your-table-from-one-file-group-to-another-file-group-move-clustered-index%2F&amp;linkname=SQL%20Server%3A%20Move%20your%20Table%20from%20one%20File%20Group%20to%20another%20File%20Group" 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%2F02%2Fsql-server-move-your-table-from-one-file-group-to-another-file-group-move-clustered-index%2F&amp;linkname=SQL%20Server%3A%20Move%20your%20Table%20from%20one%20File%20Group%20to%20another%20File%20Group" 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%2F02%2Fsql-server-move-your-table-from-one-file-group-to-another-file-group-move-clustered-index%2F&amp;linkname=SQL%20Server%3A%20Move%20your%20Table%20from%20one%20File%20Group%20to%20another%20File%20Group" 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%2F02%2Fsql-server-move-your-table-from-one-file-group-to-another-file-group-move-clustered-index%2F&amp;linkname=SQL%20Server%3A%20Move%20your%20Table%20from%20one%20File%20Group%20to%20another%20File%20Group" 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%2F02%2Fsql-server-move-your-table-from-one-file-group-to-another-file-group-move-clustered-index%2F&amp;linkname=SQL%20Server%3A%20Move%20your%20Table%20from%20one%20File%20Group%20to%20another%20File%20Group" 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%2F02%2Fsql-server-move-your-table-from-one-file-group-to-another-file-group-move-clustered-index%2F&amp;linkname=SQL%20Server%3A%20Move%20your%20Table%20from%20one%20File%20Group%20to%20another%20File%20Group" 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%2F02%2Fsql-server-move-your-table-from-one-file-group-to-another-file-group-move-clustered-index%2F&#038;title=SQL%20Server%3A%20Move%20your%20Table%20from%20one%20File%20Group%20to%20another%20File%20Group" data-a2a-url="https://www.dbrnd.com/2017/02/sql-server-move-your-table-from-one-file-group-to-another-file-group-move-clustered-index/" data-a2a-title="SQL Server: Move your Table from one File Group to another File Group"></a></p><p>If you are finding most top 10 steps for SQL Server Performance tuning, you could get one of the items in the list is &#8220;multiple file-groups and various data-files increases the query performance&#8221;.This is correct.</p>
<blockquote><p>You can move your fat table from master or primary data group to another custom file group.<br />
It gives you more performance and very easy to do maintenance.</p></blockquote>
<blockquote><p>I am also asking this question to SQL DBA like &#8220;how to move a table from one File Group to another File Group?&#8221; and most of the times I am getting answers like &#8220;Create new file group -&gt; Replicate table schema -&gt; Move data -&gt; Drop old table&#8221;.</p></blockquote>
<p>The above answer is right, but instead of this great exercise, we can move a table to new file group by creating a clustered index only.</p>
<p>Here, You can access full demonstration.<br />
<strong>Create a sample table:</strong></p><pre class="crayon-plain-tag">CREATE TABLE tbl_Students 
(
	StudID INT IDENTITY(1,1)
	,Name VARCHAR(10)
	,CONSTRAINT pk_tbl_Students_StudID PRIMARY KEY(StudID)
)
GO</pre><p>
<strong>Insert few dummies record:</strong></p><pre class="crayon-plain-tag">INSERT INTO tbl_Students(Name) VALUES ('Anvesh')
GO 100000</pre><p>
<strong>Check the table Information:</strong></p><pre class="crayon-plain-tag">EXEC SP_HELP 'tbl_Students'
GO</pre><p>
<img fetchpriority="high" decoding="async" class="alignnone wp-image-4534 size-full" title="SQL Server File Group Migration " src="https://www.dbrnd.com/wp-content/uploads/2017/02/SQLServerFileGroupMigration_1.png" alt="SQL Server File Group Migration " width="846" height="411" srcset="https://www.dbrnd.com/wp-content/uploads/2017/02/SQLServerFileGroupMigration_1.png 846w, https://www.dbrnd.com/wp-content/uploads/2017/02/SQLServerFileGroupMigration_1-300x146.png 300w, https://www.dbrnd.com/wp-content/uploads/2017/02/SQLServerFileGroupMigration_1-750x364.png 750w, https://www.dbrnd.com/wp-content/uploads/2017/02/SQLServerFileGroupMigration_1-150x73.png 150w" sizes="(max-width: 846px) 100vw, 846px" /></p>
<p><strong>Alter a database to add new file group:</strong></p><pre class="crayon-plain-tag">ALTER DATABASE Database_Name ADD FILEGROUP New_FileGroup
GO</pre><p>
<strong>Add new data file (.ndf):</strong></p><pre class="crayon-plain-tag">ALTER DATABASE Database_Name  ADD FILE
(
	NAME = 'New_DataFile', 
	FILENAME = 'C:\TempSQLData\New_DataFile.ndf',
	SIZE = 100000KB,
	FILEGROWTH = 65000KB
) TO FILEGROUP New_FileGroup
GO</pre><p>
<strong>Create a new CLUSTERED index on table within created new file group:</strong></p><pre class="crayon-plain-tag">CREATE UNIQUE CLUSTERED INDEX pk_tbl_Students_StudID ON tbl_Students(StudID)
WITH
(
	DROP_EXISTING = ON
)
ON New_FileGroup
GO</pre><p>
<strong>Check the table information:</strong></p><pre class="crayon-plain-tag">EXEC SP_HELP 'tbl_Students'
GO</pre><p>
<img decoding="async" class="alignnone wp-image-4535 size-full" title="SQLServer File Group Migration 2" src="https://www.dbrnd.com/wp-content/uploads/2017/02/SQLServerFileGroupMigration_2.png" alt="SQLServer File Group Migration 2" width="851" height="407" srcset="https://www.dbrnd.com/wp-content/uploads/2017/02/SQLServerFileGroupMigration_2.png 851w, https://www.dbrnd.com/wp-content/uploads/2017/02/SQLServerFileGroupMigration_2-300x143.png 300w, https://www.dbrnd.com/wp-content/uploads/2017/02/SQLServerFileGroupMigration_2-750x359.png 750w, https://www.dbrnd.com/wp-content/uploads/2017/02/SQLServerFileGroupMigration_2-150x72.png 150w" sizes="(max-width: 851px) 100vw, 851px" /></p>
<p><strong>If you need a space of old table, you can shrink your database:</strong><br />
<pre class="crayon-plain-tag">DBCC SHRINKFILE ('Database_Name' , 0)
GO</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2017/02/sql-server-move-your-table-from-one-file-group-to-another-file-group-move-clustered-index/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<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-3)</title>
		<link>https://www.dbrnd.com/2016/06/sql-server-database-indexes-interview-questions-and-answers-unique-filtered-covered-index-scan-seek-day-3/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Fri, 10 Jun 2016 16:50:10 +0000</pubDate>
				<category><![CDATA[SQL Server Interview]]></category>
		<category><![CDATA[answers]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[clustered index]]></category>
		<category><![CDATA[covered index]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Filtered Index]]></category>
		<category><![CDATA[indexes]]></category>
		<category><![CDATA[Interviews]]></category>
		<category><![CDATA[questions]]></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=2950</guid>

					<description><![CDATA[What happened when we create a Primary Key constraint? When you create a PRIMARY KEY constraint, a unique clustered index on the column or columns is automatically created if a clustered index on the table does not already exist and you do not specify a unique nonclustered index. The primary key column cannot allow NULL [&#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-unique-filtered-covered-index-scan-seek-day-3%2F&amp;linkname=SQL%20Server%3A%20Database%20Indexes%20Interview%20Questions%20and%20Answers%20%28Day-3%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-unique-filtered-covered-index-scan-seek-day-3%2F&amp;linkname=SQL%20Server%3A%20Database%20Indexes%20Interview%20Questions%20and%20Answers%20%28Day-3%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-unique-filtered-covered-index-scan-seek-day-3%2F&amp;linkname=SQL%20Server%3A%20Database%20Indexes%20Interview%20Questions%20and%20Answers%20%28Day-3%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-unique-filtered-covered-index-scan-seek-day-3%2F&amp;linkname=SQL%20Server%3A%20Database%20Indexes%20Interview%20Questions%20and%20Answers%20%28Day-3%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-unique-filtered-covered-index-scan-seek-day-3%2F&amp;linkname=SQL%20Server%3A%20Database%20Indexes%20Interview%20Questions%20and%20Answers%20%28Day-3%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-unique-filtered-covered-index-scan-seek-day-3%2F&amp;linkname=SQL%20Server%3A%20Database%20Indexes%20Interview%20Questions%20and%20Answers%20%28Day-3%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-unique-filtered-covered-index-scan-seek-day-3%2F&#038;title=SQL%20Server%3A%20Database%20Indexes%20Interview%20Questions%20and%20Answers%20%28Day-3%29" data-a2a-url="https://www.dbrnd.com/2016/06/sql-server-database-indexes-interview-questions-and-answers-unique-filtered-covered-index-scan-seek-day-3/" data-a2a-title="SQL Server: Database Indexes Interview Questions and Answers (Day-3)"></a></p><p><strong>What happened when we create a Primary Key constraint?</strong></p>
<blockquote><p>When you create a PRIMARY KEY constraint, a unique clustered index on the column or columns is automatically created if a clustered index on the table does not already exist and you do not specify a unique nonclustered index. The primary key column cannot allow NULL values.</p></blockquote>
<p><strong>What happened when we create a UNIQUE constraint?</strong></p>
<blockquote><p>When you create a UNIQUE constraint, a unique nonclustered index is created to enforce a UNIQUE constraint by default. You can specify a unique clustered index if a clustered index on the table does not already exist.</p></blockquote>
<p><strong>Can you create UNIQUE INDEX on a single column , which has NULL value in more than one row?</strong></p>
<blockquote><p>You cannot create a unique index on a single column if that column contains NULL in more than one row. Similarly, you cannot create a unique index on multiple columns if the combination of columns contains NULL in more than one row. These are treated as duplicate values for indexing purposes.</p></blockquote>
<p><strong>What are the benefits of a Unique Index?</strong></p>
<blockquote><p>Multicolumn unique indexes guarantee that each combination of values in the index key is unique. For example, if a unique index is created on a combination of LastName, FirstName, and MiddleName columns, no two rows in the table could have the same combination of values for these columns.</p>
<p>Provided that the data in each column is unique, you can create both a unique clustered index and multiple unique nonclustered indexes on the same table.</p>
<p>Unique indexes ensure the data integrity of the defined columns.</p>
<p>Unique indexes provide additional information helpful to the query optimizer that can produce more efficient execution plans.</p></blockquote>
<p><strong>When we should consider a Filtered Index in Designing?</strong></p>
<blockquote><p>When a column only has a small number of relevant values for queries, you can create a filtered index on the subset of values. For example, when the values in a column are mostly NULL and the query selects only from the non-NULL values, you can create a filtered index for the non-NULL data rows. The resulting index will be smaller and cost less to maintain than a full-table nonclustered index defined on the same key columns.</p>
<p>When a table has heterogeneous data rows, you can create a filtered index for one or more categories of data. This can improve the performance of queries on these data rows by narrowing the focus of a query to a specific area of the table. Again, the resulting index will be smaller and cost less to maintain than a full-table nonclustered index.</p></blockquote>
<p><strong>What are the benefits of the Filtered Index?</strong></p>
<ul>
<li>Improved query performance and plan quality.</li>
<li>Reduced index maintenance costs.</li>
<li>Reduced index storage costs.</li>
<li>Online index rebuilds.</li>
</ul>
<p><strong>What is the advantage of Covered Index?</strong></p>
<blockquote><p>There can be data types which not allowed as Index key columns called as a nonkey columns.</p>
<p>Using include keyword you can add nonkey columns in the primary index.</p>
<p>An index with nonkey columns can significantly improve query performance when all columns in the query are included in the index either as key or nonkey columns. Performance gains are achieved because the query optimizer can locate all the column values within the index; table or clustered index data is not accessed resulting in fewer disk I/O operations.</p></blockquote>
<p><strong>During an index reorganization operation, if the index spans multiple files, will pages be allowed to migrate between files.</strong></p>
<blockquote><p>No: pages will not migrate between files during an index reorganization.</p></blockquote>
<p><strong>How to make forcefully use an index in a query? Or What table hint needs to be specified to forcefully use an index in a query?</strong></p>
<p>We can specify “Index” table hint in a query to forcefully use an index.</p><pre class="crayon-plain-tag">SELECT Emp_ID, Name FROM tbl_Employee WITH(INDEX(idx_tbl_Employee_Name));</pre><p>
<strong>What kind of data structure is an index?</strong></p>
<blockquote><p>B- trees are the most commonly used data structures for indexes. The reason B- trees are the most popular data structure for indexes is due to the fact that they are time efficient because look-ups, deletions, and insertions can all be done in logarithmic time. And, another major reason B- trees are more commonly used is because the data that is stored inside the B- tree can be sorted.</p></blockquote>
<p><strong>Can you create Indexed Views?</strong></p>
<blockquote><p>The first index created on a view must be a unique clustered index. After the unique clustered index has been created, you can create more nonclustered indexes. Creating a unique clustered index on a view improves query performance because the view is stored in the database in the same way a table with a clustered index is stored. The query optimizer may use indexed views to speed up the query execution.</p></blockquote>
<p><strong>What is an Index Scan and Index Seek operation?</strong></p>
<blockquote class="wp-embedded-content" data-secret="A130fkGdes"><p><a href="https://www.dbrnd.com/2016/04/database-theory-table-scan-vs-index-scan-vs-index-seek/">Database Theory: Table Scan vs Index Scan vs Index Seek</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/04/database-theory-table-scan-vs-index-scan-vs-index-seek/embed/#?secret=A130fkGdes" data-secret="A130fkGdes" width="600" height="338" title="&#8220;Database Theory: Table Scan vs Index Scan vs Index Seek&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p><strong>What is a Database Engine Tuning Advisor in the SQL Server?</strong></p>
<blockquote><p>Microsoft SQL Server Database Engine Tuning Advisor helps you select and create an optimal set of indexes, indexed views, and partitions without requiring an expert understanding of the structure of the database or the internals of Microsoft SQL Server.</p>
<p>Database Engine Tuning Advisor analyzes a workload and the physical implementation of one or more databases. A workload is a set of Transact-SQL statements that execute against a database or databases that you want to tune. Database Engine Tuning Advisor uses trace files, trace tables, or Transact-SQL scripts as workload input when tuning databases.</p></blockquote>
<p><strong>How Index partitioning help in improving overall performance?</strong></p>
<blockquote><p>Although partitioned indexes can be implemented independently from their base tables, it generally makes sense to design a partitioned table and then create an index on the table. When you do this, SQL Server automatically partitions the index by using the same partition scheme and partitioning column as the table.</p>
<p>When a table and its indexes are in alignment, SQL Server can switch partitions quickly and efficiently while maintaining the partition structure of both the table and its indexes.</p></blockquote>
<p><strong>What is a Bookmark Lookup operator in SQL Server?</strong></p>
<blockquote><p>The Bookmark Lookup operator uses a bookmark (row ID or clustering key) to look up the corresponding row in the table or clustered index. The Argument column contains the bookmark label used to look up the row in the table or clustered index.</p></blockquote>
<p><strong>Which Index operations do not required additional Disk Space?</strong></p>
<ul>
<li>ALTER INDEX REORGANIZE; however, log space is required.</li>
<li>DROP INDEX when you are dropping a nonclustered index.</li>
<li>DROP INDEX when you are dropping a clustered index offline without specifying the MOVE TO clause and nonclustered indexes do not exist.</li>
<li>CREATE TABLE (PRIMARY KEY or UNIQUE constraints)</li>
</ul>
]]></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>
