<?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>Nonclustered Index - Techyaz.com</title>
	<atom:link href="https://techyaz.com/tag/nonclustered-index/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>Tips, Tutorials and How-to Topics</description>
	<lastBuildDate>Fri, 01 Jun 2018 12:40:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.1</generator>

<image>
	<url>https://techyaz.com/wp-content/uploads/2017/11/cropped-Site-icon-150x150.png</url>
	<title>Nonclustered Index - Techyaz.com</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Disk and Performance Impact of Online Index Rebuild Operation</title>
		<link>https://techyaz.com/sql-server/indexes/performing-online-index-rebuild-operation/</link>
					<comments>https://techyaz.com/sql-server/indexes/performing-online-index-rebuild-operation/#respond</comments>
		
		<dc:creator><![CDATA[Manvendra Deo Singh]]></dc:creator>
		<pubDate>Fri, 29 Dec 2017 12:18:51 +0000</pubDate>
				<category><![CDATA[Indexes]]></category>
		<category><![CDATA[Performance Tuning]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server Administration]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Clustered Index]]></category>
		<category><![CDATA[Index]]></category>
		<category><![CDATA[index rebuild]]></category>
		<category><![CDATA[Nonclustered Index]]></category>
		<category><![CDATA[SQL Server Indexes]]></category>
		<guid isPermaLink="false">http://techyaz.com/?p=1421</guid>

					<description><![CDATA[<p>Here, we are going to talk about disk and performance Impact of online Index rebuild operation. As we know index rebuild is offline operation due to which indexes become inaccessible. Here, I will describe about SQL Server rebuild index online&#46;&#46;&#46;</p>
<p>The post <a href="https://techyaz.com/sql-server/indexes/performing-online-index-rebuild-operation/">Disk and Performance Impact of Online Index Rebuild Operation</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Here, we are going to talk about disk and performance Impact of online Index rebuild operation. As we know index rebuild is offline operation due to which indexes become inaccessible. Here, I will describe about SQL Server rebuild index online that will keep SQL Server indexes accessible. I hope you are aware about the<strong> <a href="http://techyaz.com/sql-server/difference-index-rebuild-reorganize/" target="_blank" rel="noopener">difference between Index rebuild and Index reorganize operation</a>.</strong> If you are not aware please have a look at attached article. Index Reorganize is already an online operation whereas Index rebuild can be done using offline as well as online method. Performing online index operations include index creation, index rebuild and drop indexes. I will describe online rebuild index operation and its impact on disk and performance in this article and same concept will be applied to online index creation and online indexe drop as well.</p>
<p>There is new feature called <em>Resumable Online Index Rebuild</em> introduced in SQL Server 2017 that is an extension of online index rebuild operation. Learn about<strong> <a href="http://techyaz.com/sql-server/use-resumable-online-index-rebuild-operation-sql-server/" target="_blank" rel="noopener">Resumable Online Index Rebuild</a></strong> operation in SQL Server 2017 in attached article.</p>
<p><em><span style="color: #800000;"><strong>Read More:</strong></span></em></p>
<ul>
<li><strong><a href="http://techyaz.com/sql-server/what-should-be-the-best-value-for-fill-factor-in-sql-server/" target="_blank" rel="noopener">What should be best value for fill factor in SQL Server?</a></strong></li>
<li><strong><a href="http://techyaz.com/sql-server/how-to-avoid-page-split-in-sql-server/" target="_blank" rel="noopener">How to Avoid Page Split in SQL Server?</a></strong></li>
<li><strong><a href="http://techyaz.com/sql-server/use-resumable-online-index-rebuild-operation-sql-server/" target="_blank" rel="noopener">How to use Resumable Online Rebuild Operation?</a></strong></li>
</ul>
<h3><span style="color: #333399;">ONLINE Index Rebuild Operation</span></h3>
<p>Rebuilding an index drops and re-creates the index. Indexes becomes unavailable during this exercise that causes an outage for that object. Microsoft has given a solution to avoid inaccessibility of the object during index rebuild operation. We can specify ONLINE keyword value as ON in CREATE INDEX or ALTER INDEX to rebuild indexes online.</p>
<p><img fetchpriority="high" decoding="async" class="size-full wp-image-1423 alignleft" src="http://techyaz.com/wp-content/uploads/2017/12/Perform-Online-Index-Operations.png" alt="Online index operation" width="560" height="315" srcset="https://techyaz.com/wp-content/uploads/2017/12/Perform-Online-Index-Operations.png 560w, https://techyaz.com/wp-content/uploads/2017/12/Perform-Online-Index-Operations-300x169.png 300w" sizes="(max-width: 560px) 100vw, 560px" /></p>
<p>When you are rebuilding an index and the ONLINE option is set to ON, the underlying objects, the tables and associated indexes, are available for queries and data modification. Row versioning is used to allow for transactional consistency. SQL Server reindex ONLINE option does not work if your table has BLOB data types or index is an XML index or Spatial index.</p>
<p>I have given the list of T-SQL statements that will rebuild indexes ONLINE on your table. You just need to change the index name, table name and column name from below statements.</p>
<p>Below SQL code will rebuild the clustered index on column <strong>EMPID</strong> on the table <strong>dbo.Salary</strong>. As we are rebuilding this cluster index using dropping and recreating the cluster indexes so existing index will be dropped in the process, but it will be available during the operation because the ONLINE option is specified.</p>
<pre class="brush:sql;"><strong><span style="color: #0000ff;">CREATE CLUSTERED INDEX CI_Salary_EMPID ON dbo.Salary(EMPID)
WITH(DROP_EXISTING = ON, ONLINE = ON)
</span></strong></pre>
<p>We can also use ALTER INDEX statement to rebuild a specific index or all indexes on a specified table. The ONLINE syntax remains the same as the CREATE INDEX statement if you want to run this operation online.</p>
<pre class="brush:sql;"><strong><span style="color: #0000ff;">ALTER INDEX ALL ON [dbo.Salary]
REBUILD WITH(ONLINE = ON)
</span></strong></pre>
<p>Above statement will rebuild all indexes on table Salary keeping everything accessible during this operation. Now, we can also rebuild clustered index only on the dbo.Salary table. The ONLINE option is specified, which means that the table will be accessible during the rebuild operation.</p>
<pre class="brush:sql;"><strong><span style="color: #0000ff;">ALTER INDEX CI_Salary_EMPID ON dbo.salary
REBUILD WITH(ONLINE = ON)
</span></strong></pre>
<p>But if we will remove ONLINE option from above statement, then table will NOT be accessible during rebuild operation. You can run below command to validate the accessibility of your table for which you are rebuilding the indexes.</p>
<pre class="brush:sql;"><strong><span style="color: #0000ff;">ALTER INDEX CI_Salary_EMPID ON dbo.salary
REBUILD
</span></strong></pre>
<h3><span style="color: #333399;">Disk Space Considerations </span></h3>
<p>Disk space is an important consideration when you create, rebuild, or drop indexes. Inadequate disk space can degrade performance or even cause the index operation to fail. There might be other major performance impact of Online Index Rebuild operation as well. Please consider below recommendations if you are using Online index operations or during SQL Server rebuild index online.</p>
<ol>
<li>During ONLINE index rebuild and index creation, additional space is required in the data file to keep the second copy of the index. This is because SQL Server creates a snapshot of the index and once index rebuild or creation completes, second copy of this index will be removed by SQL Server.</li>
<li>Additional disk space is required for the temporary mapping index. This temporary index is used in online index operations that create, rebuild, or drop a clustered index.</li>
<li>Make sure the transaction log has been backed up and truncated before running index operations online, and that the log has sufficient space to store the projected index and user transactions.</li>
<li>Specify SORT_IN_TEMPDB option to ON for the index operation. This separates the index transactions from the concurrent user transactions. The index transactions will be stored in the tempdb transaction log, and the concurrent user transactions will be stored in the transaction log of the user database. Make sure to keep tempdb log and user database log files on separate drives to avoid any disk space issues.</li>
<li>Verify that the tempdb database and transaction log have sufficient disk space to handle the index operation. The tempdb transaction log cannot be truncated until the index operation is completed.</li>
<li>Do not run the online index operation in an explicit transaction. The log will not be truncated until the explicit transaction ends.</li>
</ol>
<h3><span style="color: #333399;">Performance Considerations</span></h3>
<p>If we think about performance impact of Online Index Rebuild operation on SQL Server then it will put more burden on your database server than offline index operations. Because both the source and target structures are maintained during the online index operation.</p>
<p>ONLINE Index operations will be slower than equivalent offline index operations because insert, update, and delete transactions is increased, potentially up to double. This could cause a decrease in performance and greater resource usage, especially CPU time, during the index operation. Online index operations are enterprise features and are fully logged operations.</p>
<p>It is recommended to use legacy way of index rebuild or index operations if your system allows a maintenance window. Remember users will be restricted to access data during the offline index operation, but the operation finishes faster and uses fewer resources.</p>
<p>If you have a system that runs 24&#215;7 then ONLINE index rebuild or creation will be a better choice but make sure to consider all points described in this article before choosing online index operations. You need to think from disk space and performance both prospect and design your system that can handle the load and sustain during peak hours.</p>
<p><em><span style="color: #800000;"><strong>Related Articles</strong></span></em></p>
<ul>
<li><strong><a href="http://techyaz.com/sql-server/sql-server-interview-questions-answers-indexes/" target="_blank" rel="noopener">SQL Server Interview Questions &amp; Answers on Indexes</a></strong></li>
<li><strong><a href="http://techyaz.com/sql-server/understanding-sql-server-indexes/" target="_blank" rel="noopener">Understanding Different types of Indexes in SQL Server</a></strong></li>
</ul>
<p>Here, I have described Disk and Performance Impact of Online Index Rebuild operation on SQL Server. I hope you like this article. Please follow our <a href="https://www.facebook.com/Techyaz/">Facebook</a> page and <a href="https://twitter.com/Tech_yaz">Twitter </a>handle to get latest updates.</p>
<p>The post <a href="https://techyaz.com/sql-server/indexes/performing-online-index-rebuild-operation/">Disk and Performance Impact of Online Index Rebuild Operation</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://techyaz.com/sql-server/indexes/performing-online-index-rebuild-operation/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server Interview Questions &#038; Answers on Indexes</title>
		<link>https://techyaz.com/interview-questions/sql-server-interview-questions/sql-server-interview-questions-answers-indexes/</link>
					<comments>https://techyaz.com/interview-questions/sql-server-interview-questions/sql-server-interview-questions-answers-indexes/#respond</comments>
		
		<dc:creator><![CDATA[Manvendra Deo Singh]]></dc:creator>
		<pubDate>Mon, 04 Dec 2017 10:05:32 +0000</pubDate>
				<category><![CDATA[Indexes]]></category>
		<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[Performance Tuning]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server Interview Questions]]></category>
		<category><![CDATA[Clustered Index]]></category>
		<category><![CDATA[DBA interview questions]]></category>
		<category><![CDATA[Interview]]></category>
		<category><![CDATA[Nonclustered Index]]></category>
		<category><![CDATA[SQL Server Indexes]]></category>
		<guid isPermaLink="false">http://techyaz.com/?p=1277</guid>

					<description><![CDATA[<p>This article is part of SQL Server interview questions &#38; answers series. Today, i am covering SQL Server Interview Questions &#38; Answers on Indexes. You can have a look at the last few series of interview questions and answers on different&#46;&#46;&#46;</p>
<p>The post <a href="https://techyaz.com/interview-questions/sql-server-interview-questions/sql-server-interview-questions-answers-indexes/">SQL Server Interview Questions &#038; Answers on Indexes</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>This article is part of SQL Server interview questions &amp; answers series. Today, i am covering SQL Server Interview Questions &amp; Answers on Indexes. You can have a look at the last few series of interview questions and answers on different SQL Server topics. Read this article to learn SQL Server interview questions on indexes.</p>
<p><em><span style="color: #800000;"><strong>Related Articles:</strong></span></em></p>
<ul>
<li><strong><a href="https://techyaz.com/sql-server/alwayson/sql-server-alwayson-interview-questions-answers/" target="_blank" rel="noopener">SQL Server Interview Q&amp;A on Alwayson Availability Group</a></strong></li>
<li><strong><a href="https://techyaz.com/interview-questions/sql-server-dba-interview-questions-answers/" target="_blank" rel="noopener">SQL Server DBA Interview Questions &amp; Answers</a></strong></li>
<li><strong><a href="https://techyaz.com/sql-server/backup-recovery/sql-server-backup-recovery-interview-questions-answers/" target="_blank" rel="noopener">SQL Server Backup &amp; Recovery Interview Questions &amp; Answers</a></strong></li>
<li><strong><a href="https://techyaz.com/interview-questions/sql-server-interview-questions-answers-architecture/" target="_blank" rel="noopener">SQL Server Architecture Interview Questions &amp; Answers</a></strong></li>
<li><strong><a href="https://techyaz.com/sql-server/difference-index-rebuild-reorganize/" target="_blank" rel="noopener">Index Rebuild vs Index Reorganize Operation</a></strong></li>
</ul>
<p><img decoding="async" class="aligncenter wp-image-1279 size-full" src="http://techyaz.com/wp-content/uploads/2017/11/SQL-Server-Interview-Questions-and-Answers-on-Indexes.png" alt="SQL Server Interview Questions and Answers on Indexes" width="560" height="315" srcset="https://techyaz.com/wp-content/uploads/2017/11/SQL-Server-Interview-Questions-and-Answers-on-Indexes.png 560w, https://techyaz.com/wp-content/uploads/2017/11/SQL-Server-Interview-Questions-and-Answers-on-Indexes-300x169.png 300w" sizes="(max-width: 560px) 100vw, 560px" /></p>
<h3><span style="color: #333399;">SQL Server Interview Questions &amp; Answers on Indexes</span></h3>
<p><strong>Question &#8211; How data stores in Indexes?</strong></p>
<p><strong>Answer &#8211; </strong>Data stores in indexes or in tables on a series of 8 kb <a href="https://techyaz.com/sql-server/understanding-sql-server-data-files-pages-extents/" target="_blank" rel="noopener">data pages</a>. <a href="https://techyaz.com/sql-server/understanding-sql-server-indexes/" target="_blank" rel="noopener">Indexes</a> Data on these data pages are organized in a B-Tree structure that supports fast retrieval of the rows, based on their index key values. Each page in an index B-tree is called an index node. The top node of the B-tree is called the root node. The bottom level of nodes in the index is called the leaf nodes. The leaf nodes of a <a href="https://techyaz.com/sql-server/understanding-sql-server-indexes/" target="_blank" rel="noopener">nonclustered index</a> is made up of index pages instead of data pages whereas in a <a href="https://techyaz.com/sql-server/understanding-sql-server-indexes/" target="_blank" rel="noopener">clustered index</a>, the leaf nodes contain the data pages.</p>
<p><strong>Question &#8211; What is Fill Factor and what should be the perfect value for it?</strong></p>
<p><strong>Answer &#8211; </strong>A fill factor value determines the percentage of space on each leaf-level page to be filled with data, reserving the remainder on each page as free space for future growth. Fill factor values 0 and 100 are the same in all respects. The fill-factor option is provided for fine-tuning index data storage and performance. Although, there is no defined value that we can say is perfect value for fill factor. You can set it to somewhere around 80% and monitor fragmentation over time. Then, you can tweak its value up or down depending on how fragmented the indexes get. Read more about <a href="https://techyaz.com/sql-server/what-should-be-the-best-value-for-fill-factor-in-sql-server/" target="_blank" rel="noopener">fill factor and its best value</a>.</p>
<p><strong>Question &#8211; Explain Page Split and whether it is good for SQL Server or bad?</strong></p>
<p><strong>Answer &#8211; </strong>Whenever you update existing rows with the data that is bigger in size to save on their data page then Page Split operation occur to make space for this new update. <a href="https://techyaz.com/sql-server/how-to-avoid-page-split-in-sql-server/" target="_blank" rel="noopener">Page split reduces performance</a> so we can say page split is not at all a good thing for our database.</p>
<p><strong>Question &#8211; How page split is bad for performance?</strong></p>
<p><strong>Answer &#8211; </strong><a href="https://techyaz.com/sql-server/how-to-avoid-page-split-in-sql-server/" target="_blank" rel="noopener">Page split is a resource intensive operation</a> and causes <a href="https://techyaz.com/sql-server/difference-index-rebuild-reorganize/" target="_blank" rel="noopener">fragmentation</a> that leads to deficient performance in terms of increased I/O operations. We should take it seriously if there are frequent page splits occur and consider reducing its occurrences</p>
<p><b>Question &#8211; What is Difference between clustered and nonclustered Indexes?</b></p>
<p><strong>Answer &#8211; </strong><a href="https://techyaz.com/sql-server/understanding-sql-server-indexes/" target="_blank" rel="noopener">Clustered indexes</a> sort and store the data rows in the table or view based on their key values. There can be only one clustered index per table, because the data rows themselves can be sorted in only one order.</p>
<p><a href="https://techyaz.com/sql-server/understanding-sql-server-indexes/" target="_blank" rel="noopener">Nonclustered indexes</a> have the same B-tree structure as clustered indexes. The data rows of the underlying table are not sorted and stored in order based on their non clustered keys. The leaf layer of a nonclustered index is made up of index pages instead of data pages. You can create up to 999 nonclustered indexes on a table.<strong> </strong></p>
<p><strong>Question &#8211; Does indexes always improve database performance?</strong></p>
<p><strong>Answer &#8211; </strong>NO, sometimes indexes can reduce your database performance if you are running a bulk data upload or your application has a nature of frequent data Insert operations. Indexes are very useful if you are accessing or reading the data.</p>
<p><strong>Question &#8211; What is filter index?</strong></p>
<p><strong>Answer &#8211;  </strong>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. <strong> </strong></p>
<p><strong>Question &#8211; What is covering index?</strong></p>
<p><strong>Answer &#8211; </strong>A covering index is one which can satisfy all requested columns in a query without performing a further lookup into the clustered index.</p>
<p><strong>Question &#8211; Explain column store index?</strong></p>
<p><strong>Answer &#8211; </strong>An in-memory columnstore index stores and manages data by using column-based data storage and column-based query processing.</p>
<p>Columnstore indexes work well for data warehousing workloads that primarily perform bulk loads and read-only queries.<strong> </strong></p>
<p><strong>Question &#8211; Why can’t a table have more than one clustered indexes?</strong></p>
<p><strong>Answer &#8211; </strong>Clustered indexes sort and store the data rows in the table or view based on their key values so you can’t store data in table based on two index key that’s why you can create only one cluster index on a table.</p>
<p><strong>Question -What is Heap and when it is useful from clustered table?</strong></p>
<p><strong>Answer &#8211; </strong>Heap is a table without having cluster indexes. Heaps are generally useful if you are running huge bulk data load or frequent DML operations.</p>
<p><strong>Question &#8211; How do you find about missing indexes that you need to create to improve database performance?</strong></p>
<p><strong>Answer &#8211; </strong>We can run SQL Server database Tuning Advisor that will suggests us about all the missing indexes that we should create to improve db performance. We can also use DMVs related to missing indexes sys.dm_db_missing_index_details, sys.dm_db_missing_index_groups and sys.dm_db_missing_index_columns to get these details.</p>
<p>I hope you like this article. Please follow our <a href="https://www.facebook.com/Techyaz/">Facebook</a> page and <a href="https://twitter.com/Tech_yaz">Twitter</a> handle to get latest updates.</p>
<p>The post <a href="https://techyaz.com/interview-questions/sql-server-interview-questions/sql-server-interview-questions-answers-indexes/">SQL Server Interview Questions &#038; Answers on Indexes</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://techyaz.com/interview-questions/sql-server-interview-questions/sql-server-interview-questions-answers-indexes/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Difference between Index Rebuild and Reorganize</title>
		<link>https://techyaz.com/sql-server/indexes/difference-index-rebuild-reorganize/</link>
					<comments>https://techyaz.com/sql-server/indexes/difference-index-rebuild-reorganize/#comments</comments>
		
		<dc:creator><![CDATA[Manvendra Deo Singh]]></dc:creator>
		<pubDate>Mon, 13 Nov 2017 07:14:21 +0000</pubDate>
				<category><![CDATA[Indexes]]></category>
		<category><![CDATA[Performance Tuning]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Clustered Index]]></category>
		<category><![CDATA[Index]]></category>
		<category><![CDATA[Nonclustered Index]]></category>
		<category><![CDATA[SQL Server Indexes]]></category>
		<guid isPermaLink="false">http://techyaz.com/?p=1133</guid>

					<description><![CDATA[<p>Fragmentation exists when indexes have pages in which the logical ordering, based on the key value, does not match the physical ordering inside the data file. Heavily fragmented indexes can degrade query performance and cause your application to respond slowly.&#46;&#46;&#46;</p>
<p>The post <a href="https://techyaz.com/sql-server/indexes/difference-index-rebuild-reorganize/">Difference between Index Rebuild and Reorganize</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Fragmentation exists when indexes have pages in which the logical ordering, based on the key value, does not match the physical ordering inside the data file. Heavily fragmented indexes can degrade query performance and cause your application to respond slowly.  We use SQL Server Index Rebuild and Reorganize operation to remove fragmentation level of the indexes. Let’s have a look at the differences between rebuild and reorganize indexes.</p>
<h3><span style="color: #333399;">Index Rebuild vs Index Reorganize</span></h3>
<p><strong>Index Rebuild</strong> operation first drops and then recreates the index. This removes fragmentation, reclaims disk space by compacting the pages based on the specified or existing fill factor setting. Microsoft recommends Index Rebuild operation to defrag indexes if the fragmentation level of your index is greater than 30%. You can execute Index rebuild operation online as well as offline. <a href="https://techyaz.com/sql-server/performing-online-index-rebuild-operation/" target="_blank" rel="noopener">Online index rebuild operation</a> is enterprise only feature and you can use it if you have SQL Server Enterprise edition.</p>
<p><strong>Reorganizing</strong> an index uses minimal system resources. It defragments the leaf level of <a href="https://techyaz.com/sql-server/understanding-sql-server-indexes/" target="_blank" rel="noopener">clustered and nonclustered indexes</a> on tables and views by physically reordering the leaf-level pages to match the logical, left to right, order of the leaf nodes. Microsoft recommends using Index Reorganize operation to defrag indexes if the fragmentation level of your index is greater than 5% and less than or equal to 30%. Reorganizing an index is always executed online.</p>
<p><span style="color: #800000;"><em><strong>Read More:</strong></em></span></p>
<ul>
<li><strong><a href="https://techyaz.com/sql-server/what-should-be-the-best-value-for-fill-factor-in-sql-server/" target="_blank" rel="noopener">What should be best value for fill factor in SQL Server?</a></strong></li>
<li><strong><a href="https://techyaz.com/sql-server/how-to-avoid-page-split-in-sql-server/" target="_blank" rel="noopener">How to Avoid Page Split in SQL Server?</a></strong></li>
<li><strong><a href="https://techyaz.com/sql-server/sql-server-interview-questions-answers-indexes/" target="_blank" rel="noopener">SQL Server Interview Questions &amp; Answers on Indexes</a></strong></li>
</ul>
<h3><span style="color: #333399;">How to Check Fragmentation Level?</span></h3>
<p>First, we detect the fragmentation level of the indexes. Once we have the details about fragmented indexes then we can decide whether to rebuild that index or reorganize it. We can get index fragmentation level using DMV sys.dm_db_index_physical_stats or by launching dashboard report. Find the average fragmentation percentage of all indexes in the table dbo.Salary of database techyaz by running below T-SQL script.</p>
<pre class="brush: sql; title: ; notranslate" title=""><strong><span style="color: #0000ff;">USE Techyaz;
GO
SELECT a.index_id, name, avg_fragmentation_in_percent
FROM sys.dm_db_index_physical_stats (DB_ID(N'Techyaz'),
OBJECT_ID(N'dbo.salary'), NULL, NULL, NULL) AS a
JOIN sys.indexes AS b
ON a.object_id = b.object_id AND a.index_id = b.index_id;
GO
</span></strong></pre>
<p>We can see the output of this code in below image. As i have only one table and two indexes in my database but if you have multiple tables and indexes then output will look accordingly.</p>
<p><img decoding="async" class="aligncenter size-full wp-image-1134" src="http://techyaz.com/wp-content/uploads/2017/11/1-Check-Fragmentation-level.jpg" alt="check fragmentation level" width="515" height="279" srcset="https://techyaz.com/wp-content/uploads/2017/11/1-Check-Fragmentation-level.jpg 515w, https://techyaz.com/wp-content/uploads/2017/11/1-Check-Fragmentation-level-300x163.jpg 300w" sizes="(max-width: 515px) 100vw, 515px" /></p>
<p>Another way to check the fragmentation level of your indexes is by running dashboard report.  Right click on your database, click on <strong>“Reports”</strong> then <strong>“Standard Reports</strong>” then finally click on <strong>“Index Physical Statistics”</strong> report. You can see this in below screenshot.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1135" src="http://techyaz.com/wp-content/uploads/2017/11/2-launch-dashboard-report.jpg" alt="Index physical statistics report" width="849" height="605" srcset="https://techyaz.com/wp-content/uploads/2017/11/2-launch-dashboard-report.jpg 849w, https://techyaz.com/wp-content/uploads/2017/11/2-launch-dashboard-report-300x214.jpg 300w, https://techyaz.com/wp-content/uploads/2017/11/2-launch-dashboard-report-768x547.jpg 768w" sizes="auto, (max-width: 849px) 100vw, 849px" /></p>
<p>Once you click on <strong>“Index Physical Statistics”</strong> report, a dashboard report will run and appear on right side pane as per below screenshot. You will get fragmentation level for each index here.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1136" src="http://techyaz.com/wp-content/uploads/2017/11/3-Dashboard-Report.jpg" alt="fragmented indexes" width="857" height="481" srcset="https://techyaz.com/wp-content/uploads/2017/11/3-Dashboard-Report.jpg 857w, https://techyaz.com/wp-content/uploads/2017/11/3-Dashboard-Report-300x168.jpg 300w, https://techyaz.com/wp-content/uploads/2017/11/3-Dashboard-Report-768x431.jpg 768w" sizes="auto, (max-width: 857px) 100vw, 857px" /></p>
<h3><span style="color: #333399;">How to Remove Fragmentation Level?</span></h3>
<p>There are two ways to remove fragmentation level of indexes. These are by either using <strong>Index Rebuild Operation</strong> or by using <strong>Index Reorganize Operation</strong>. Here, i will show you how to remove fragmentation using both ways one after another.</p>
<p><span style="color: #800000;"><strong>Remove Fragmentation using Index Reorganize Operation</strong></span></p>
<p>We can see our index has very low fragmentation level that is less than 30% in above images so we will reorganize it rather than rebuild. We will rebuild only those indexes that have more than 30% of fragmentation level. Run below T-SQL command to reorganize index IX_Salary_EMPID.</p>
<pre class="brush: sql; title: ; notranslate" title=""><strong><span style="color: #0000ff;">USE Techyaz;
GO

ALTER INDEX IX_Salary_EMPID
ON dbo.Salary
REORGANIZE ;
GO
</span></strong></pre>
<p>If you want to reorganize all indexes of this table dbo.salary in one shot, you can use <strong>ALL</strong> keyword in Alter Index command. Run below command to reorganize all indexes of table dbo.salary in one go.</p>
<pre class="brush: sql; title: ; notranslate" title=""><strong><span style="color: #0000ff;">USE Techyaz;
GO

ALTER INDEX ALL ON dbo.Salary
REORGANIZE;
GO
</span></strong></pre>
<p><span style="color: #800000;"><strong>Remove fragmentation using Index Rebuild Operation</strong></span></p>
<p>Similarly, we will rebuild all those indexes that are highly fragmented. As I don’t have any such index but if you will get any index that has more than 30% of fragmentation then you can run below command to rebuild that index.</p>
<pre class="brush: sql; title: ; notranslate" title=""><strong><span style="color: #0000ff;">USE Techyaz;
GO
ALTER INDEX PK_Salary_EMPCODE ON dbo.Salary
REBUILD;
GO
</span></strong></pre>
<p>If you want to REBUILD all indexes of dbo.salary table in go then again we will use <strong>ALL</strong> keyword in ALTER Index statement as we did in above example during REORGANIZE.</p>
<pre class="brush: sql; title: ; notranslate" title=""><strong><span style="color: #0000ff;">USE Techyaz;
GO
ALTER INDEX ALL ON dbo.Salary
REBUILD WITH (FILLFACTOR = 80, SORT_IN_TEMPDB = ON,
STATISTICS_NORECOMPUTE = ON);
GO
</span></strong></pre>
<p>If your system does not allow any maintenance window and run 24&#215;7 then you can use online method to rebuild these indexes. Read attached article to learn <a href="https://techyaz.com/sql-server/performing-online-index-rebuild-operation/" target="_blank" rel="noopener">how to rebuild indexes online in SQL Server</a>. Even SQL Server 2017 has given more control on index rebuild operation by introducing a new feature called <a href="https://techyaz.com/sql-server/use-resumable-online-index-rebuild-operation-sql-server/" target="_blank" rel="noopener">Resumable Online Index Rebuild</a>. Read the attached article to learn about this feature in which we can pause a index rebuild operation and resume it later from the point it was stopped.</p>
<p>I hope you like this article. You can drop your questions and feedback in comment section. Please follow our <a href="https://www.facebook.com/Techyaz/">Facebook</a> page and <a href="https://twitter.com/Tech_yaz">Twitter </a>handle to get latest updates.</p>
<p>The post <a href="https://techyaz.com/sql-server/indexes/difference-index-rebuild-reorganize/">Difference between Index Rebuild and Reorganize</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://techyaz.com/sql-server/indexes/difference-index-rebuild-reorganize/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>What should be the Best Value for Fill Factor in SQL Server</title>
		<link>https://techyaz.com/sql-server/indexes/what-should-be-the-best-value-for-fill-factor-in-sql-server/</link>
					<comments>https://techyaz.com/sql-server/indexes/what-should-be-the-best-value-for-fill-factor-in-sql-server/#respond</comments>
		
		<dc:creator><![CDATA[Manvendra Deo Singh]]></dc:creator>
		<pubDate>Fri, 10 Nov 2017 11:47:04 +0000</pubDate>
				<category><![CDATA[Indexes]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Clustered Index]]></category>
		<category><![CDATA[fill factor]]></category>
		<category><![CDATA[Index]]></category>
		<category><![CDATA[Nonclustered Index]]></category>
		<category><![CDATA[SQL Server Indexes]]></category>
		<guid isPermaLink="false">http://techyaz.com/?p=1125</guid>

					<description><![CDATA[<p>Lot of SQL Server resources ask what is the best value for fill factor in SQL Server and should we change its value from default to some other value? On high level, generally we should not change fill factor value&#46;&#46;&#46;</p>
<p>The post <a href="https://techyaz.com/sql-server/indexes/what-should-be-the-best-value-for-fill-factor-in-sql-server/">What should be the Best Value for Fill Factor in SQL Server</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Lot of SQL Server resources ask what is the best value for fill factor in SQL Server and should we change its value from default to some other value? On high level, generally we should not change fill factor value from its default value but you should analyze the history and based on its fragmentation frequency you can take the call. Here, I will show you how to check fill factor in SQL Server and also its best value that you should keep in your database.</p>
<p>A fill factor value determines the percentage of space on each leaf-level page to be filled with data, reserving the remainder on each page as free space for future growth. For example, If we specify a fill factor value of 95 means that 5% of each leaf-level page will be left empty, providing space for future index expansion as data is added to the underlying table. The empty space is reserved between the <a href="https://techyaz.com/sql-server/understanding-sql-server-indexes/" target="_blank" rel="noopener">index</a> rows rather than at the end of the index.</p>
<p>Fill factor values 0 and 100 are the same in all respects. The fill-factor option is provided for fine-tuning index data storage and performance. Setting inappropriate fillfactor value will increase the page split occurrence that is not good from SQL Server performance point of view. A correctly chosen value can reduce potential page splits by providing enough space for index expansion.</p>
<p>Although, there is no defined value that we can say is perfect value for fill factor. You can set it to somewhere around 80% and monitor fragmentation over time. Then, you can tweak its value up or down depending on how fragmented the indexes get.</p>
<p>There is a myth that Database engine considers fill factor value during every INSERT or UPDATE transaction. But it&#8217;s not true. Database engine does not consider fill factor value during normal DML (insert / update / delete) operations. This value comes into picture only during index creation or rebuild operation. So whenever you insert or load data in your database data pages will be filled 100% irrespective of your fill-factor value.</p>
<h3><span style="color: #333399;">How to specify a fill factor in an index by using GUI in SSMS</span></h3>
<ol>
<li>Connect to <strong>SQL Server Instance</strong> using SSMS.</li>
<li>Expand <strong>Database</strong> folder followed by the <strong>database that contains the table</strong> on which you want to specify an index’s fill factor.</li>
<li>Expand the <strong>Tables </strong>folder.</li>
<li>Click the plus sign to expand the table on which you want to specify an index fill-factor.</li>
<li>Click the plus sign to expand the <strong>Indexes</strong></li>
<li>Right-click the index with the fill factor that you want to specify and select <strong>Properties</strong>.</li>
<li>Under <strong>Select a page</strong>, select <strong>Options</strong>.</li>
<li>In the <strong>Fill factor </strong>row, enter the fill factor that you want.</li>
<li>Click <strong>OK</strong>.</li>
</ol>
<p>You can check fill factor value in below screenshot as well. Fill factor value is showing zero because of its default value. Change it for this particular index if you want.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1138" src="http://techyaz.com/wp-content/uploads/2017/11/fill-factor.jpg" alt="fill factor" width="854" height="530" srcset="https://techyaz.com/wp-content/uploads/2017/11/fill-factor.jpg 854w, https://techyaz.com/wp-content/uploads/2017/11/fill-factor-300x186.jpg 300w, https://techyaz.com/wp-content/uploads/2017/11/fill-factor-768x477.jpg 768w" sizes="auto, (max-width: 854px) 100vw, 854px" /></p>
<h3><span style="color: #333399;"><strong>How to specify a fill factor in an index using Transact-SQL</strong></span></h3>
<p>We can determine fill factor either during <a href="https://techyaz.com/sql-server/difference-index-rebuild-reorganize/" target="_blank" rel="noopener">Index REBUILD operation</a> or during Index creation. Below is the T-SQL codes that we can use to specify fill factor for an index.</p>
<p><strong>To specify a fill factor in an existing index</strong></p>
<p>Run below T-SQL command to determine fill factor for an existing index during Rebuild operation.</p>
<pre class="brush: sql; title: ; notranslate" title=""><strong><span style="color: #008000;">-- Rebuilds the IX_Salary_EMPID index with a fill-factor of 95 on the dbo.Salary table.</span></strong>
<span style="color: #0000ff;"><strong>USE Techyaz
GO

ALTER INDEX IX_Salary_EMPID ON dbo.Salary
REBUILD WITH (<span style="color: #ff0000;">FILLFACTOR = 95</span>);
GO
</strong></span></pre>
<p><strong>To specify a fill-factor during create index</strong></p>
<p>Run below command to specify a fill-factor during index creation.</p>
<pre class="brush: sql; title: ; notranslate" title=""><span style="color: #008000;"><strong>--Drops and re-creates the IX_Salary_EMPID index on the dbo.Salary table with a fill-factor of 95.</strong></span>
<strong><span style="color: #0000ff;">USE Techyaz;
GO

CREATE INDEX IX_Salary_EMPID ON dbo.Salary
(EMPID)
WITH (DROP_EXISTING = ON, <span style="color: #ff0000;">FILLFACTOR = 95</span>);
GO
</span></strong></pre>
<p><em><span style="color: #800000;"><strong>Related Articles</strong></span></em></p>
<ul>
<li><strong><a href="https://techyaz.com/sql-server/understanding-sql-server-indexes/" target="_blank" rel="noopener">Understanding SQL Server Indexes</a></strong></li>
<li><strong><a href="https://techyaz.com/sql-server/difference-index-rebuild-reorganize/" target="_blank" rel="noopener">What is difference between Rebuild and Reorganize Indexes?</a></strong></li>
<li><strong><a href="https://techyaz.com/sql-server/troubleshooting/table-row-count-showing-incorrect-value-sys-partitions-dmv-sys-dm_db_partition_stats/" target="_blank" rel="noopener">Table Row Count is showing incorrect in sys.partitions</a></strong></li>
<li><strong><a href="https://techyaz.com/sql-server/get-row-counts-tables-database/" target="_blank" rel="noopener">How to get Total Row Count of all tables of a database</a></strong></li>
</ul>
<p>I hope you like this article. Drop your questions and feedbacks in comment section. Please follow our <a href="https://www.facebook.com/Techyaz/">Facebook</a> page and <a href="https://twitter.com/Tech_yaz">Twitter </a>handle to get latest updates.</p>
<p>The post <a href="https://techyaz.com/sql-server/indexes/what-should-be-the-best-value-for-fill-factor-in-sql-server/">What should be the Best Value for Fill Factor in SQL Server</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://techyaz.com/sql-server/indexes/what-should-be-the-best-value-for-fill-factor-in-sql-server/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Understanding SQL Server Indexes</title>
		<link>https://techyaz.com/sql-server/indexes/understanding-sql-server-indexes/</link>
					<comments>https://techyaz.com/sql-server/indexes/understanding-sql-server-indexes/#respond</comments>
		
		<dc:creator><![CDATA[Manvendra Deo Singh]]></dc:creator>
		<pubDate>Thu, 09 Nov 2017 10:50:08 +0000</pubDate>
				<category><![CDATA[Indexes]]></category>
		<category><![CDATA[Performance Tuning]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Clustered Index]]></category>
		<category><![CDATA[Index]]></category>
		<category><![CDATA[Nonclustered Index]]></category>
		<category><![CDATA[SQL Server Indexes]]></category>
		<category><![CDATA[SQL_Server_Architecture]]></category>
		<guid isPermaLink="false">http://techyaz.com/?p=1114</guid>

					<description><![CDATA[<p>SQL Server Indexes are similar to book indexes that we use to search any content in that book. They are very useful in faster data retrieval or data access. We create index on columns of tables or views. An index is&#46;&#46;&#46;</p>
<p>The post <a href="https://techyaz.com/sql-server/indexes/understanding-sql-server-indexes/">Understanding SQL Server Indexes</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>SQL Server Indexes are similar to book indexes that we use to search any content in that book. They are very useful in faster data retrieval or data access. We create index on columns of tables or views. An index is made up of a set of pages (index nodes) that are organized in a B-tree structure. A B-tree structure has three levels.</p>
<ul>
<li>Root Level</li>
<li>Intermediate Level</li>
<li>leaf Level.</li>
</ul>
<p>Clustered index leaf-level pages contain the data in the table whereas Non Clustered index leaf-level pages contain the key value and a pointer to the data row in the clustered index or heap.</p>
<p><span style="color: #800000;"><em><strong>Read More</strong></em></span></p>
<ul>
<li><strong><a href="https://techyaz.com/sql-server/use-resumable-online-index-rebuild-operation-sql-server/" target="_blank" rel="noopener">How to use Resumable Online Index Rebuild Operation?</a></strong></li>
<li><strong><a href="https://techyaz.com/sql-server/performing-online-index-rebuild-operation/" target="_blank" rel="noopener">Understanding Online Index Rebuild Operation</a></strong></li>
<li><strong><a href="https://techyaz.com/sql-server/sql-server-interview-questions-answers-indexes/attachment/sql-server-interview-questions-and-answers-on-indexes/" target="_blank" rel="noopener">SQL Server Interview Questions &amp; Answers on Indexes</a></strong></li>
</ul>
<p>If your table does not have SQL Server indexes and you want to access data from the table then database engine will take more time and performance because full table scan will be performed to get that data. However, if your table has an index on column, SQL Server can seek directly on the value and retrieve the rows.</p>
<p><img loading="lazy" decoding="async" class="wp-image-1116 size-medium alignleft" src="http://techyaz.com/wp-content/uploads/2017/11/Index-e1510224779231-300x249.jpg" alt="SQL Server Index" width="300" height="249" srcset="https://techyaz.com/wp-content/uploads/2017/11/Index-e1510224779231-300x249.jpg 300w, https://techyaz.com/wp-content/uploads/2017/11/Index-e1510224779231.jpg 719w" sizes="auto, (max-width: 300px) 100vw, 300px" /></p>
<h4><span style="color: #333399;">Index Types</span></h4>
<p>There are multiple types of indexes in SQL Server. Below is the list of such indexes.</p>
<h5><span style="color: #800000;">Clustered Index</span></h5>
<ul>
<li>Clustered indexes sort and store the data rows in the table or view based on their key values. There can be only one clustered index per table, because the data rows themselves can be sorted in only one order.</li>
<li>The only time the data rows in a table are stored in sorted order is when the table contains a clustered index. When a table has a clustered index, the table is called a clustered table. If a table has no clustered index, its data rows are stored in an unordered structure called a heap.</li>
</ul>
<h5><span style="color: #800000;">Nonclustered Index</span></h5>
<ul>
<li>Nonclustered indexes have the same B-tree structure as clustered indexes.</li>
<li>The data rows of the underlying table are not sorted and stored in order based on their nonclustered keys.</li>
<li>The leaf layer of a nonclustered index is made up of index pages instead of data pages.</li>
<li>You can create upto 999 nonclustered indexes on a table.</li>
</ul>
<h5><span style="color: #800000;">Memory-optimized nonclustered indexes</span></h5>
<ul>
<li>For memory-optimized nonclustered indexes, memory consumption is a function of the row count and the size of the index key columns</li>
</ul>
<h5><span style="color: #800000;">Hash Index</span></h5>
<ul>
<li>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.</li>
</ul>
<h5><span style="color: #800000;">Unique  Index</span></h5>
<ul>
<li>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. Uniqueness can be a property of both clustered and nonclustered indexes.</li>
</ul>
<h5><span style="color: #800000;">Columnstore Index</span></h5>
<ul>
<li>An in-memory columnstore index stores and manages data by using column-based data storage and column-based query processing.</li>
<li>Columnstore indexes work well for data warehousing workloads that primarily perform bulk loads and read-only queries.</li>
<li>Use the columnstore index to achieve up to 10x query performance gains over traditional row-oriented storage, and up to 7x data compression over the uncompressed data size.</li>
</ul>
<h5><span style="color: #800000;">Index with included columns</span></h5>
<ul>
<li>A nonclustered index that is extended to include nonkey columns in addition to the key columns.</li>
</ul>
<h5><span style="color: #800000;">Index on computed columns  </span></h5>
<ul>
<li>An index on a column that is derived from the value of one or more other columns, or certain deterministic inputs.</li>
</ul>
<h5><span style="color: #800000;">Filtered Index</span></h5>
<ul>
<li>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.</li>
</ul>
<h5><span style="color: #800000;">Spatial  Index</span></h5>
<ul>
<li>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.</li>
</ul>
<h5><span style="color: #800000;">XML Index</span></h5>
<ul>
<li>A shredded, and persisted, representation of the XML binary large objects (BLOBs) in the xml data type column.</li>
</ul>
<h5><span style="color: #800000;">Full-text Index</span></h5>
<ul>
<li>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.</li>
</ul>
<h4><span style="color: #333399;">How SQL Server Indexes are used by Query Optimizer</span></h4>
<p>When a query is executed, the query optimizer evaluates each available method for retrieving the data and selects the most efficient method. The method may be a table scan, or may be scanning one or more indexes if they exist. When performing a table scan, the query optimizer reads all the rows in the table, and extracts the rows that meet the criteria of the query. A table scan generates many disk I/O operations and can be resource intensive. However, a table scan could be the most efficient method if, for example, the result set of the query is a high percentage of rows from the table.</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>
<p>Your task is to design and create SQL Server indexes that are best suited to your environment so that the query optimizer has a selection of efficient indexes from which to select. SQL Server provides the Database Engine Tuning Advisor to help with the analysis of your database environment and in the selection of appropriate indexes.</p>
<p>I hope you like this article. Please follow our <a href="https://www.facebook.com/Techyaz/">Facebook</a> page and <a href="https://twitter.com/Tech_yaz">Twitter </a>handle to get latest updates.</p>
<p>The post <a href="https://techyaz.com/sql-server/indexes/understanding-sql-server-indexes/">Understanding SQL Server Indexes</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://techyaz.com/sql-server/indexes/understanding-sql-server-indexes/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
