<?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>index &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/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>Mon, 24 Jun 2019 19:36:06 +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: Script to find the total size of the Indexes</title>
		<link>https://www.dbrnd.com/2019/05/sql-server-script-to-find-the-total-size-of-the-indexes/</link>
					<comments>https://www.dbrnd.com/2019/05/sql-server-script-to-find-the-total-size-of-the-indexes/#respond</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 27 May 2019 16:16:18 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[duplicate index]]></category>
		<category><![CDATA[fragmentation]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[redundant 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=4191</guid>

					<description><![CDATA[In this post, I am sharing one script to find the size of Indexes in SQL Server. The first step for performance optimization is to measure the size of tables and indexes which helps you to find out more about fragmentation. I have already shared a couple of articles on SQL Server Indexes like: find [&#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%2F2019%2F05%2Fsql-server-script-to-find-the-total-size-of-the-indexes%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20total%20size%20of%20the%20Indexes" 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%2F2019%2F05%2Fsql-server-script-to-find-the-total-size-of-the-indexes%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20total%20size%20of%20the%20Indexes" 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%2F2019%2F05%2Fsql-server-script-to-find-the-total-size-of-the-indexes%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20total%20size%20of%20the%20Indexes" 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%2F2019%2F05%2Fsql-server-script-to-find-the-total-size-of-the-indexes%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20total%20size%20of%20the%20Indexes" 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%2F2019%2F05%2Fsql-server-script-to-find-the-total-size-of-the-indexes%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20total%20size%20of%20the%20Indexes" 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%2F2019%2F05%2Fsql-server-script-to-find-the-total-size-of-the-indexes%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20total%20size%20of%20the%20Indexes" 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%2F2019%2F05%2Fsql-server-script-to-find-the-total-size-of-the-indexes%2F&#038;title=SQL%20Server%3A%20Script%20to%20find%20the%20total%20size%20of%20the%20Indexes" data-a2a-url="https://www.dbrnd.com/2019/05/sql-server-script-to-find-the-total-size-of-the-indexes/" data-a2a-title="SQL Server: Script to find the total size of the Indexes"></a></p><p>In this post, I am sharing one script to find the size of Indexes in SQL Server.</p>
<blockquote><p>The first step for performance optimization is to measure the size of tables and indexes which helps you to find out more about fragmentation.</p></blockquote>
<p>I have already shared a couple of articles on SQL Server Indexes like: find duplicate indexes, unused indexes and fragmentation of indexes. </p>
<p>You can also access these articles after below T-SQL. </p>
<pre class="crayon-plain-tag">SELECT
	OBJECT_SCHEMA_NAME(i.OBJECT_ID) AS SchemaName
	,OBJECT_NAME(i.OBJECT_ID) AS TableName
	,i.name AS IndexName
	,8 * SUM(au.used_pages) AS IndexSizeInKB
FROM sys.indexes AS i
JOIN sys.partitions AS p 
	ON p.OBJECT_ID = i.OBJECT_ID 
		AND p.index_id = i.index_id
JOIN sys.allocation_units AS au 
	ON au.container_id = p.partition_id
GROUP BY 
	i.OBJECT_ID
	,i.index_id
	,i.name
ORDER BY OBJECT_NAME(i.OBJECT_ID),i.index_id</pre> </p>
<p><strong>Other related articles:</strong></p>
<blockquote class="wp-embedded-content" data-secret="iWrp53ltXi"><p><a href="https://www.dbrnd.com/2016/04/sql-server-find-the-total-row-count-and-size-of-the-tables/">SQL Server: Find the total row count and size of the Tables</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/04/sql-server-find-the-total-row-count-and-size-of-the-tables/embed/#?secret=iWrp53ltXi" data-secret="iWrp53ltXi" width="600" height="338" title="&#8220;SQL Server: Find the total row count and size of the Tables&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote class="wp-embedded-content" data-secret="kFuNrnjgJI"><p><a href="https://www.dbrnd.com/2016/11/sql-server-script-to-find-redundant-and-duplicate-indexes/">SQL Server: Script to find Redundant and Duplicate Indexes</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/11/sql-server-script-to-find-redundant-and-duplicate-indexes/embed/#?secret=kFuNrnjgJI" data-secret="kFuNrnjgJI" width="600" height="338" title="&#8220;SQL Server: Script to find Redundant and Duplicate Indexes&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote class="wp-embedded-content" data-secret="CLStlFpaQE"><p><a href="https://www.dbrnd.com/2015/10/sql-server-script-to-find-usage-of-database-indexes/">SQL Server: Script to find usage of Database Indexes</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2015/10/sql-server-script-to-find-usage-of-database-indexes/embed/#?secret=CLStlFpaQE" data-secret="CLStlFpaQE" width="600" height="338" title="&#8220;SQL Server: Script to find usage of Database Indexes&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote class="wp-embedded-content" data-secret="CuRotuXr6g"><p><a href="https://www.dbrnd.com/2016/03/sql-server-script-to-find-index-average-fragmentation-in-percentage/">SQL Server: Script to find Index Average Fragmentation in Percentage</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/03/sql-server-script-to-find-index-average-fragmentation-in-percentage/embed/#?secret=CuRotuXr6g" data-secret="CuRotuXr6g" width="600" height="338" title="&#8220;SQL Server: Script to find Index Average Fragmentation in Percentage&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2019/05/sql-server-script-to-find-the-total-size-of-the-indexes/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>PostgreSQL: Create Index using ORDER BY (ASC/DESC)</title>
		<link>https://www.dbrnd.com/2017/12/postgresql-create-index-using-order-by-ascdesc/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sat, 16 Dec 2017 16:16:31 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[index order by]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Monitoring]]></category>
		<category><![CDATA[PostgreSQL Performance Tuning]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=6816</guid>

					<description><![CDATA[Recently, I received a message like &#8220;ORDER BY clause is not working in PostgreSQL Index&#8221;. One of the users created an index with ORDER BY DESC and whenever he was selecting data at that time Query optimizer was not using INDEX SCAN ONLY. So here, I demonstrate and validate this: If we know in which [&#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%2F12%2Fpostgresql-create-index-using-order-by-ascdesc%2F&amp;linkname=PostgreSQL%3A%20Create%20Index%20using%20ORDER%20BY%20%28ASC%2FDESC%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%2F2017%2F12%2Fpostgresql-create-index-using-order-by-ascdesc%2F&amp;linkname=PostgreSQL%3A%20Create%20Index%20using%20ORDER%20BY%20%28ASC%2FDESC%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%2F2017%2F12%2Fpostgresql-create-index-using-order-by-ascdesc%2F&amp;linkname=PostgreSQL%3A%20Create%20Index%20using%20ORDER%20BY%20%28ASC%2FDESC%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%2F2017%2F12%2Fpostgresql-create-index-using-order-by-ascdesc%2F&amp;linkname=PostgreSQL%3A%20Create%20Index%20using%20ORDER%20BY%20%28ASC%2FDESC%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%2F2017%2F12%2Fpostgresql-create-index-using-order-by-ascdesc%2F&amp;linkname=PostgreSQL%3A%20Create%20Index%20using%20ORDER%20BY%20%28ASC%2FDESC%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%2F2017%2F12%2Fpostgresql-create-index-using-order-by-ascdesc%2F&amp;linkname=PostgreSQL%3A%20Create%20Index%20using%20ORDER%20BY%20%28ASC%2FDESC%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%2F2017%2F12%2Fpostgresql-create-index-using-order-by-ascdesc%2F&#038;title=PostgreSQL%3A%20Create%20Index%20using%20ORDER%20BY%20%28ASC%2FDESC%29" data-a2a-url="https://www.dbrnd.com/2017/12/postgresql-create-index-using-order-by-ascdesc/" data-a2a-title="PostgreSQL: Create Index using ORDER BY (ASC/DESC)"></a></p><p>Recently, I received a message like &#8220;ORDER BY clause is not working in PostgreSQL Index&#8221;.</p>
<p>One of the users created an index with ORDER BY DESC and whenever he was selecting data at that time Query optimizer was not using INDEX SCAN ONLY.</p>
<p><strong>So here, I demonstrate and validate this: </strong></p>
<blockquote><p>
If we know in which order we are going to SELECT data, we should apply for proper ORDER BY ASC/DESC in the index.</p></blockquote>
<p><strong>Please check the below full demonstration, and then validate your self:</strong></p>
<p><strong>Create a table with sample records:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_testIndex(a INTEGER, b INTEGER);

INSERT INTO tbl_testIndex
SELECT x, x FROM generate_series(1, 5000) AS f(x);</pre> </p>
<p><strong>Create a sample index without any ORDER BY:</strong></p>
<pre class="crayon-plain-tag">CREATE INDEX tbl_testIndex_idx ON tbl_testIndex (a, b);</pre> </p>
<p><strong>Check the execution plan:</strong><br />
Index only scan is working&#8230;</p>
<pre class="crayon-plain-tag">EXPLAIN 
SELECT *FROM tbl_testIndex
ORDER BY a,b;

'Index Only Scan using 
tbl_testindex_idx on tbl_testindex  
(cost=0.28..194.16 rows=5000 width=8)'</pre> </p>
<p><strong>Check the below execution plan:</strong><br />
Sequential Scan of the index which is not good.<br />
Because the index is not available for ORDER BY b DESC. </p>
<pre class="crayon-plain-tag">EXPLAIN 
SELECT *FROM tbl_testIndex
ORDER BY a,b DESC;

'Sort  (cost=380.19..392.69 rows=5000 width=8)'
'  Sort Key: a, b DESC'
'  -&gt;  Seq Scan on tbl_testindex  
(cost=0.00..73.00 rows=5000 width=8)'</pre> </p>
<p><strong>Now, drop the old index:</strong></p>
<pre class="crayon-plain-tag">DROP INDEX tbl_testIndex_idx;</pre> </p>
<p><strong>Create a new index with b DESC:</strong></p>
<pre class="crayon-plain-tag">CREATE INDEX tbl_testIndex_idx ON tbl_testIndex (a, b DESC);</pre> </p>
<p><strong>Check the below execution plan:</strong><br />
Index scan is working&#8230;</p>
<pre class="crayon-plain-tag">EXPLAIN 
SELECT *FROM tbl_testIndex
ORDER BY a,b DESC;

'Index Only Scan using 
tbl_testindex_idx on tbl_testindex  
(cost=0.28..194.16 rows=5000 width=8)'</pre> </p>
<p><strong>Check the below execution plans:</strong><br />
You can find sequential scan of index because we are not using only ORDER BY b DESC</p>
<pre class="crayon-plain-tag">EXPLAIN 
SELECT *FROM tbl_testIndex
ORDER BY a,b;

EXPLAIN 
SELECT *FROM tbl_testIndex
ORDER BY a DESC,b DESC;

'Sort  (cost=380.19..392.69 rows=5000 width=8)'
'  Sort Key: a DESC, b DESC'
'  -&gt;  Seq Scan on tbl_testindex  
(cost=0.00..73.00 rows=5000 width=8)'</pre> </p>
<p><strong>Now, check the below execution plan:</strong><br />
You can find like Index scan backward, where we gave ORDER By a DESC and internally, it is using backward index scan.</p>
<pre class="crayon-plain-tag">EXPLAIN 
SELECT *FROM tbl_testIndex
ORDER BY a DESC,b;

'Index Only Scan Backward using 
tbl_testindex_idx on tbl_testindex  
(cost=0.28..194.16 rows=5000 width=8)'</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server 2014: WAIT_AT_LOW_PRIORITY improved the performance of ONLINE REBUILD INDEX operation</title>
		<link>https://www.dbrnd.com/2017/11/sql-server-2014-wait_at_low_priority-improved-the-performance-of-online-rebuild-index-operation/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sun, 12 Nov 2017 16:16:59 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[BLOCKER]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[MAX_DURATION]]></category>
		<category><![CDATA[REBUILD]]></category>
		<category><![CDATA[Rebuild Index]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server 2014]]></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>
		<category><![CDATA[WAIT_AT_LOW_PRIORITY]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=6113</guid>

					<description><![CDATA[SQL Server 2014 introduced WAIT_AT_LOW_PRIORITY option which enhanced the performance of ONLINE REBUILD INDEX. In the previous version of SQL Server, REBUILD INDEX had to wait for the running transaction. But now in SQL Server 2014, you can give options like MAX_DURATION in minutes, ABORT_AFTER_WAIT with different options. For ABORT_AFTER_WAIT, took the reference from Microsoft: [&#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%2F11%2Fsql-server-2014-wait_at_low_priority-improved-the-performance-of-online-rebuild-index-operation%2F&amp;linkname=SQL%20Server%202014%3A%20WAIT_AT_LOW_PRIORITY%20improved%20the%20performance%20of%20ONLINE%20REBUILD%20INDEX%20operation" 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%2F11%2Fsql-server-2014-wait_at_low_priority-improved-the-performance-of-online-rebuild-index-operation%2F&amp;linkname=SQL%20Server%202014%3A%20WAIT_AT_LOW_PRIORITY%20improved%20the%20performance%20of%20ONLINE%20REBUILD%20INDEX%20operation" 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%2F11%2Fsql-server-2014-wait_at_low_priority-improved-the-performance-of-online-rebuild-index-operation%2F&amp;linkname=SQL%20Server%202014%3A%20WAIT_AT_LOW_PRIORITY%20improved%20the%20performance%20of%20ONLINE%20REBUILD%20INDEX%20operation" 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%2F11%2Fsql-server-2014-wait_at_low_priority-improved-the-performance-of-online-rebuild-index-operation%2F&amp;linkname=SQL%20Server%202014%3A%20WAIT_AT_LOW_PRIORITY%20improved%20the%20performance%20of%20ONLINE%20REBUILD%20INDEX%20operation" 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%2F11%2Fsql-server-2014-wait_at_low_priority-improved-the-performance-of-online-rebuild-index-operation%2F&amp;linkname=SQL%20Server%202014%3A%20WAIT_AT_LOW_PRIORITY%20improved%20the%20performance%20of%20ONLINE%20REBUILD%20INDEX%20operation" 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%2F11%2Fsql-server-2014-wait_at_low_priority-improved-the-performance-of-online-rebuild-index-operation%2F&amp;linkname=SQL%20Server%202014%3A%20WAIT_AT_LOW_PRIORITY%20improved%20the%20performance%20of%20ONLINE%20REBUILD%20INDEX%20operation" 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%2F11%2Fsql-server-2014-wait_at_low_priority-improved-the-performance-of-online-rebuild-index-operation%2F&#038;title=SQL%20Server%202014%3A%20WAIT_AT_LOW_PRIORITY%20improved%20the%20performance%20of%20ONLINE%20REBUILD%20INDEX%20operation" data-a2a-url="https://www.dbrnd.com/2017/11/sql-server-2014-wait_at_low_priority-improved-the-performance-of-online-rebuild-index-operation/" data-a2a-title="SQL Server 2014: WAIT_AT_LOW_PRIORITY improved the performance of ONLINE REBUILD INDEX operation"></a></p><p>SQL Server 2014 introduced WAIT_AT_LOW_PRIORITY option which enhanced the performance of ONLINE REBUILD INDEX.</p>
<blockquote><p>In the previous version of SQL Server, REBUILD INDEX had to wait for the running transaction.<br />
But now in SQL Server 2014, you can give options like MAX_DURATION in minutes, ABORT_AFTER_WAIT with different options.</p></blockquote>
<p><a href="https://docs.microsoft.com/en-us/sql/t-sql/statements/alter-index-transact-sql" target="_blank" rel="noopener noreferrer">For ABORT_AFTER_WAIT, took the reference from Microsoft:</a></p><pre class="crayon-plain-tag">ABORT_AFTER_WAIT = [NONE | SELF | BLOCKERS]</pre><p>
<strong>NONE:</strong> Continue waiting for the lock with normal (regular) priority.</p>
<p><strong>SELF:</strong> Exit the online index rebuild DDL operation currently being executed without taking any action.</p>
<p><strong>BLOCKERS:</strong> Kill all user transactions that block the online index rebuild DDL operation so that the operation can continue. The BLOCKERS option requires the login to have ALTER ANY CONNECTION permission.</p>
<p><strong>Please check the below demonstration, where I am comparing old and new approach of REBUILD INDEX:</strong></p>
<p><strong>Create a sample table:</strong></p><pre class="crayon-plain-tag">CREATE TABLE tbl_DumpData
(
	ID INT 
	,RandomID VARCHAR(MAX)
	,CONSTRAINT pk_tbl_DumpData_ID PRIMARY KEY(ID)
)
GO</pre><p>
<p><strong>Insert dummy data:</strong></p><pre class="crayon-plain-tag">;WITH CTE AS
(
	SELECT 1 ID
	UNION all
	SELECT ID + 1
	FROM CTE   
	WHERE ID + 1 &lt;= 100000
)
INSERT INTO tbl_DumpData(ID,RandomID)
SELECT 
	ID
	,NEWID() AS RandomID
FROM CTE 
OPTION (MAXRECURSION 0)
GO</pre><p>
<p><strong>Open new session/query window, execute below update:</strong></p><pre class="crayon-plain-tag">BEGIN TRANSACTION
UPDATE tbl_DumpData SET RandomID = 39840972340234 WHERE ID = 8</pre><p>
<p><strong>Jump to old session window, and execute below REBUILD:</strong><br />
<em>It is Running&#8230; Running&#8230; Running&#8230;, because table is locked by another transaction</em></p><pre class="crayon-plain-tag">ALTER INDEX pk_tbl_DumpData_ID ON tbl_DumpData REBUILD
WITH
(
   ONLINE = ON
)
GO</pre><p>
<p><strong>Check the lock table:</strong><br />
You can find that your REBUILD query is in WAIT mode.</p><pre class="crayon-plain-tag">SELECT *FROM sys.dm_tran_locks</pre><p>
<img loading="lazy" decoding="async" class="alignnone size-full wp-image-6115" src="https://www.dbrnd.com/wp-content/uploads/2017/09/SQLIndexLock.png" alt="SQL Index Lock" width="740" height="136" srcset="https://www.dbrnd.com/wp-content/uploads/2017/09/SQLIndexLock.png 740w, https://www.dbrnd.com/wp-content/uploads/2017/09/SQLIndexLock-679x125.png 679w" sizes="auto, (max-width: 740px) 100vw, 740px" /></p>
<p><strong>Now stop the execution of the previous REBUILD, and execute below REBUILD WITH WAIT_AT_LOW_PRIORITY:</strong><br />
Set MAX_DURATION for one minute and ABORT_AFTER_WAIT type is SELF.<br />
<pre class="crayon-plain-tag">ALTER INDEX pk_tbl_DumpData_ID ON tbl_DumpData REBUILD
WITH
(
   ONLINE = ON
   (
	WAIT_AT_LOW_PRIORITY 
	(
		MAX_DURATION = 1
		,ABORT_AFTER_WAIT = SELF
	)
   )
)
GO</pre>
<p><strong>Above REBUILD will wait for One minute and then it will throw an error message:</strong><br />
<pre class="crayon-plain-tag">Msg 1222, Level 16, State 56, Line 1
Lock request time out period exceeded.</pre>
<p><strong>Now, test with BLOCKER option:</strong><br />
It will wait for one minute, and then it will kill the open UPDATE transaction to finish the REBUILD operation.<br />
<pre class="crayon-plain-tag">ALTER INDEX pk_tbl_DumpData_ID ON tbl_DumpData REBUILD
WITH
(
   ONLINE = ON
   (
	WAIT_AT_LOW_PRIORITY 
	(
		MAX_DURATION = 1
		,ABORT_AFTER_WAIT = BLOCKERS 
	)
   )
)
GO</pre>
<p><strong>Now, go to another transaction where UPDATE transaction was there:</strong><br />
Try to execute any query, you will get below error message because this session is terminated by REBUILD + BLOCKERS.<br />
<pre class="crayon-plain-tag">SELECT *FROM tbl_DumpData</pre>
<p><strong>Error:</strong><br />
<pre class="crayon-plain-tag">Msg 0, Level 20, State 0, Line 0
The connection is broken and recovery is not possible.  The connection is marked by the server as unrecoverable.  No attempt was made to restore the connection.</pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server: Use sp_MSforeachtable to apply a T-SQL command to every table of current Database</title>
		<link>https://www.dbrnd.com/2017/09/sql-server-use-sp_msforeachtable-to-apply-a-t-sql-command-to-every-table-of-current-database/</link>
					<comments>https://www.dbrnd.com/2017/09/sql-server-use-sp_msforeachtable-to-apply-a-t-sql-command-to-every-table-of-current-database/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sat, 02 Sep 2017 16:16:15 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[sp_msforeachtable]]></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[Table]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=6013</guid>

					<description><![CDATA[In this post, I am sharing the use of sp_MSforeachtable stored procedure of SQL Server. This is an undocumented object of SQL Server, but still, you can use this stored procedure. When we require executing same T-SQL command for all the tables, we can use this stored procedure. Many times we need to run drop/truncate [&#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%2F09%2Fsql-server-use-sp_msforeachtable-to-apply-a-t-sql-command-to-every-table-of-current-database%2F&amp;linkname=SQL%20Server%3A%20Use%20sp_MSforeachtable%20to%20apply%20a%20T-SQL%20command%20to%20every%20table%20of%20current%20Database" 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%2F09%2Fsql-server-use-sp_msforeachtable-to-apply-a-t-sql-command-to-every-table-of-current-database%2F&amp;linkname=SQL%20Server%3A%20Use%20sp_MSforeachtable%20to%20apply%20a%20T-SQL%20command%20to%20every%20table%20of%20current%20Database" 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%2F09%2Fsql-server-use-sp_msforeachtable-to-apply-a-t-sql-command-to-every-table-of-current-database%2F&amp;linkname=SQL%20Server%3A%20Use%20sp_MSforeachtable%20to%20apply%20a%20T-SQL%20command%20to%20every%20table%20of%20current%20Database" 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%2F09%2Fsql-server-use-sp_msforeachtable-to-apply-a-t-sql-command-to-every-table-of-current-database%2F&amp;linkname=SQL%20Server%3A%20Use%20sp_MSforeachtable%20to%20apply%20a%20T-SQL%20command%20to%20every%20table%20of%20current%20Database" 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%2F09%2Fsql-server-use-sp_msforeachtable-to-apply-a-t-sql-command-to-every-table-of-current-database%2F&amp;linkname=SQL%20Server%3A%20Use%20sp_MSforeachtable%20to%20apply%20a%20T-SQL%20command%20to%20every%20table%20of%20current%20Database" 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%2F09%2Fsql-server-use-sp_msforeachtable-to-apply-a-t-sql-command-to-every-table-of-current-database%2F&amp;linkname=SQL%20Server%3A%20Use%20sp_MSforeachtable%20to%20apply%20a%20T-SQL%20command%20to%20every%20table%20of%20current%20Database" 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%2F09%2Fsql-server-use-sp_msforeachtable-to-apply-a-t-sql-command-to-every-table-of-current-database%2F&#038;title=SQL%20Server%3A%20Use%20sp_MSforeachtable%20to%20apply%20a%20T-SQL%20command%20to%20every%20table%20of%20current%20Database" data-a2a-url="https://www.dbrnd.com/2017/09/sql-server-use-sp_msforeachtable-to-apply-a-t-sql-command-to-every-table-of-current-database/" data-a2a-title="SQL Server: Use sp_MSforeachtable to apply a T-SQL command to every table of current Database"></a></p><p>In this post, I am sharing the use of sp_MSforeachtable stored procedure of SQL Server.<br />
This is an undocumented object of SQL Server, but still, you can use this stored procedure.</p>
<blockquote><p>When we require executing same T-SQL command for all the tables, we can use this stored procedure.<br />
Many times we need to run drop/truncate command for all tables or REINDEX all tables, at that point instead of the manual script we can use this stored procedure.</p></blockquote>
<p><strong>Sharing few examples:</strong></p>
<p><strong>Truncate all tables of current database:</strong></p>
<pre class="crayon-plain-tag">EXEC sp_MSforeachtable 'TRUNCATE TABLE ?'</pre> </p>
<p><strong>Check the count of all tables:</strong></p>
<pre class="crayon-plain-tag">EXEC sp_MSforeachtable 'TRUNCATE TABLE ?'</pre> </p>
<p><strong>Drop all tables of current database:</strong></p>
<pre class="crayon-plain-tag">EXEC sp_MSforeachtable 'DROP TABLE ?'</pre> </p>
<p><strong>REINDEX all tables of current database:</strong></p>
<pre class="crayon-plain-tag">EXEC sp_MSforeachtable 'DBCC DBREINDEX(''?'')'</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2017/09/sql-server-use-sp_msforeachtable-to-apply-a-t-sql-command-to-every-table-of-current-database/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server Interview: Which Index uses by COUNT(*) statement</title>
		<link>https://www.dbrnd.com/2017/07/sql-server-interview-which-index-uses-by-count-statement/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 17 Jul 2017 16:16:36 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server Interview]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[COUNT(*)]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[index]]></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=5628</guid>

					<description><![CDATA[In this post, I am sharing an interesting SQL Server Interview Question which may ask in the interview of SQL Server Database Developer. As a database developer, we are executing COUNT(*) many times to check the total number of table records. But have you ever check the execution plan of your COUNT(*) statement? If your [&#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%2F07%2Fsql-server-interview-which-index-uses-by-count-statement%2F&amp;linkname=SQL%20Server%20Interview%3A%20Which%20Index%20uses%20by%20COUNT%28%2A%29%20statement" 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%2F07%2Fsql-server-interview-which-index-uses-by-count-statement%2F&amp;linkname=SQL%20Server%20Interview%3A%20Which%20Index%20uses%20by%20COUNT%28%2A%29%20statement" 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%2F07%2Fsql-server-interview-which-index-uses-by-count-statement%2F&amp;linkname=SQL%20Server%20Interview%3A%20Which%20Index%20uses%20by%20COUNT%28%2A%29%20statement" 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%2F07%2Fsql-server-interview-which-index-uses-by-count-statement%2F&amp;linkname=SQL%20Server%20Interview%3A%20Which%20Index%20uses%20by%20COUNT%28%2A%29%20statement" 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%2F07%2Fsql-server-interview-which-index-uses-by-count-statement%2F&amp;linkname=SQL%20Server%20Interview%3A%20Which%20Index%20uses%20by%20COUNT%28%2A%29%20statement" 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%2F07%2Fsql-server-interview-which-index-uses-by-count-statement%2F&amp;linkname=SQL%20Server%20Interview%3A%20Which%20Index%20uses%20by%20COUNT%28%2A%29%20statement" 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%2F07%2Fsql-server-interview-which-index-uses-by-count-statement%2F&#038;title=SQL%20Server%20Interview%3A%20Which%20Index%20uses%20by%20COUNT%28%2A%29%20statement" data-a2a-url="https://www.dbrnd.com/2017/07/sql-server-interview-which-index-uses-by-count-statement/" data-a2a-title="SQL Server Interview: Which Index uses by COUNT(*) statement"></a></p><p>In this post, I am sharing an interesting SQL Server Interview Question which may ask in the interview of SQL Server Database Developer.</p>
<p>As a database developer, we are executing COUNT(*) many times to check the total number of table records. But have you ever check the execution plan of your COUNT(*) statement?</p>
<blockquote><p><strong>If your answer is No</strong>, then you should check below demonstration.<br />
<strong>If your answer is Yes</strong>, then don&#8217;t be surprised by checking below demonstration because COUNT(*) statement first uses a lightweight index of a table. If an index does not present, it will do a Table Scan.</p></blockquote>
<p><strong>Create a table with sample data:</strong></p><pre class="crayon-plain-tag">CREATE TABLE tbl_Count
(ID1 INT IDENTITY, ID2 SMALLINT DEFAULT 1, Name CHAR(500) DEFAULT 'dbrnd.com')

INSERT INTO tbl_Count DEFAULT VALUES;
GO 10000</pre><p>
<strong>Check query execution plan of COUNT statement:</strong><br />
It performed Table scan because didn&#8217;t find any indexes on a table.</p><pre class="crayon-plain-tag">SELECT COUNT(1) FROM tbl_Count</pre><p>
<img loading="lazy" decoding="async" class="alignnone size-full wp-image-5632" src="https://www.dbrnd.com/wp-content/uploads/2017/07/CountQueryPlan1.png" alt="Count Query Plan table scan" width="517" height="129" /></p>
<p><strong>Now create an index on NAME column:</strong></p><pre class="crayon-plain-tag">CREATE NONCLUSTERED INDEX idx_tbl_Count_Name ON tbl_Count (Name)
GO</pre><p>
<strong>Check query execution plan of COUNT statement:</strong><br />
You can find Index scan for idx_tbl_Count_Name.</p><pre class="crayon-plain-tag">SELECT COUNT(1) FROM tbl_Count</pre><p>
<img loading="lazy" decoding="async" class="alignnone size-full wp-image-5633" src="https://www.dbrnd.com/wp-content/uploads/2017/07/CountQueryPlan2.png" alt="Count Query Plan Index Scan" width="659" height="138" /></p>
<p><strong>Now create an index on ID2 column:</strong></p><pre class="crayon-plain-tag">CREATE NONCLUSTERED INDEX idx_tbl_Count_ID2 ON tbl_Count (ID2)
GO</pre><p>
<strong>Check query execution plan of COUNT statement:</strong><br />
You can find Index scan for idx_tbl_Count_ID2 (smallint) because it lightweight than idx_tbl_Count_Name (char).</p><pre class="crayon-plain-tag">SELECT COUNT(1) FROM tbl_Count</pre><p>
<img loading="lazy" decoding="async" class="alignnone size-full wp-image-5634" src="https://www.dbrnd.com/wp-content/uploads/2017/07/CountQueryPlan3.png" alt="Count Query Plan Index Scan" width="646" height="134" /></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server Interview: Can disable the Index, If yes, how to verify disable indexes?</title>
		<link>https://www.dbrnd.com/2017/05/sql-server-interview-can-disable-the-index-if-yes-how-to-verify-disable-indexes/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Tue, 16 May 2017 16:16:47 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server Interview]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Disable Index]]></category>
		<category><![CDATA[Enable Index]]></category>
		<category><![CDATA[index]]></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=5079</guid>

					<description><![CDATA[This post is for SQL Server developers who are in intermediate level. Why people are asking this question because when you are performing any optimization related activity at that time, you need to test lots of indexes. In that case, I have found many of developers who are dropping and creating indexes again and again [&#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%2F05%2Fsql-server-interview-can-disable-the-index-if-yes-how-to-verify-disable-indexes%2F&amp;linkname=SQL%20Server%20Interview%3A%20Can%20disable%20the%20Index%2C%20If%20yes%2C%20how%20to%20verify%20disable%20indexes%3F" 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%2F05%2Fsql-server-interview-can-disable-the-index-if-yes-how-to-verify-disable-indexes%2F&amp;linkname=SQL%20Server%20Interview%3A%20Can%20disable%20the%20Index%2C%20If%20yes%2C%20how%20to%20verify%20disable%20indexes%3F" 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%2F05%2Fsql-server-interview-can-disable-the-index-if-yes-how-to-verify-disable-indexes%2F&amp;linkname=SQL%20Server%20Interview%3A%20Can%20disable%20the%20Index%2C%20If%20yes%2C%20how%20to%20verify%20disable%20indexes%3F" 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%2F05%2Fsql-server-interview-can-disable-the-index-if-yes-how-to-verify-disable-indexes%2F&amp;linkname=SQL%20Server%20Interview%3A%20Can%20disable%20the%20Index%2C%20If%20yes%2C%20how%20to%20verify%20disable%20indexes%3F" 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%2F05%2Fsql-server-interview-can-disable-the-index-if-yes-how-to-verify-disable-indexes%2F&amp;linkname=SQL%20Server%20Interview%3A%20Can%20disable%20the%20Index%2C%20If%20yes%2C%20how%20to%20verify%20disable%20indexes%3F" 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%2F05%2Fsql-server-interview-can-disable-the-index-if-yes-how-to-verify-disable-indexes%2F&amp;linkname=SQL%20Server%20Interview%3A%20Can%20disable%20the%20Index%2C%20If%20yes%2C%20how%20to%20verify%20disable%20indexes%3F" 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%2F05%2Fsql-server-interview-can-disable-the-index-if-yes-how-to-verify-disable-indexes%2F&#038;title=SQL%20Server%20Interview%3A%20Can%20disable%20the%20Index%2C%20If%20yes%2C%20how%20to%20verify%20disable%20indexes%3F" data-a2a-url="https://www.dbrnd.com/2017/05/sql-server-interview-can-disable-the-index-if-yes-how-to-verify-disable-indexes/" data-a2a-title="SQL Server Interview: Can disable the Index, If yes, how to verify disable indexes?"></a></p><p>This post is for SQL Server developers who are in intermediate level. Why people are asking this question because when you are performing any optimization related activity at that time, you need to test lots of indexes. </p>
<p>In that case, I have found many of developers who are dropping and creating indexes again and again for their testing purpose.</p>
<blockquote><p>If you are good T-SQL Developer, you must know that you can also enable and disable the indexes. So I am sharing this interview question&#8230;</p></blockquote>
<p><strong>How to disable the index?</strong></p>
<pre class="crayon-plain-tag">ALTER INDEX index_name ON table_name DISABLE
GO</pre> </p>
<p><strong>How to enable the index?</strong></p>
<pre class="crayon-plain-tag">ALTER INDEX index_name ON table_name REBUILD
GO</pre> </p>
<p><strong>How to check the status?</strong></p>
<pre class="crayon-plain-tag">SELECT	  
	name AS IndexName
	,type_desc AS IndexType
	, CASE IS_DISABLED
			WHEN 0 THEN 'Enabled'
			ELSE 'Disabled'
	END AS IndexStatus
FROM SYS.INDEXES</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server Interview: Difference between Filtered Index and Table Partition</title>
		<link>https://www.dbrnd.com/2017/03/sql-server-interview-difference-between-filtered-index-and-table-partition/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sat, 18 Mar 2017 16:16:40 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server Interview]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Filtered Index]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[partition function]]></category>
		<category><![CDATA[Partition scheme]]></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[Table Partition]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4773</guid>

					<description><![CDATA[If you are SQL DBA and if I am taking your interview, definitely I will ask this question to you. If you don&#8217;t know about Filtered Index and how to create a Table Partition in SQL Server, please visit below articles: SQL Server: Filtered Indexes &#8211; Improved the query performance SQL Server 2016: Introduce New [&#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-interview-difference-between-filtered-index-and-table-partition%2F&amp;linkname=SQL%20Server%20Interview%3A%20Difference%20between%20Filtered%20Index%20and%20Table%20Partition" 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-interview-difference-between-filtered-index-and-table-partition%2F&amp;linkname=SQL%20Server%20Interview%3A%20Difference%20between%20Filtered%20Index%20and%20Table%20Partition" 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-interview-difference-between-filtered-index-and-table-partition%2F&amp;linkname=SQL%20Server%20Interview%3A%20Difference%20between%20Filtered%20Index%20and%20Table%20Partition" 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-interview-difference-between-filtered-index-and-table-partition%2F&amp;linkname=SQL%20Server%20Interview%3A%20Difference%20between%20Filtered%20Index%20and%20Table%20Partition" 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-interview-difference-between-filtered-index-and-table-partition%2F&amp;linkname=SQL%20Server%20Interview%3A%20Difference%20between%20Filtered%20Index%20and%20Table%20Partition" 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-interview-difference-between-filtered-index-and-table-partition%2F&amp;linkname=SQL%20Server%20Interview%3A%20Difference%20between%20Filtered%20Index%20and%20Table%20Partition" 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-interview-difference-between-filtered-index-and-table-partition%2F&#038;title=SQL%20Server%20Interview%3A%20Difference%20between%20Filtered%20Index%20and%20Table%20Partition" data-a2a-url="https://www.dbrnd.com/2017/03/sql-server-interview-difference-between-filtered-index-and-table-partition/" data-a2a-title="SQL Server Interview: Difference between Filtered Index and Table Partition"></a></p><p>If you are SQL DBA and if I am taking your interview, definitely I will ask this question to you.<br />
If you don&#8217;t know about Filtered Index and how to create a Table Partition in SQL Server, please visit below articles:</p>
<blockquote class="wp-embedded-content" data-secret="JVP5sA9RpP"><p><a href="https://www.dbrnd.com/2017/01/sql-server-filtered-indexes-improved-the-query-performance/">SQL Server: Filtered Indexes &#8211; Improved the query performance</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2017/01/sql-server-filtered-indexes-improved-the-query-performance/embed/#?secret=JVP5sA9RpP" data-secret="JVP5sA9RpP" width="600" height="338" title="&#8220;SQL Server: Filtered Indexes &#8211; Improved the query performance&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote class="wp-embedded-content" data-secret="n6fhw7WVTT"><p><a href="https://www.dbrnd.com/2016/01/sql-server-2016-introduce-new-truncate-by-partitions-number/">SQL Server 2016: Introduce New TRUNCATE  by Partitions Number</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/01/sql-server-2016-introduce-new-truncate-by-partitions-number/embed/#?secret=n6fhw7WVTT" data-secret="n6fhw7WVTT" width="600" height="338" title="&#8220;SQL Server 2016: Introduce New TRUNCATE  by Partitions Number&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p><strong>Filtered Index:</strong></p>
<ul>
<li>You can store a portion of your dataset in Filtered Index. For example, Created a filtered index on Gender column for only &#8216;Male&#8217;, then it stores only &#8216;Male&#8217; detailed index data.</li>
<li>Filtered index only applies to a subset of the base table which is not allowing a fast switching.</li>
<li>You can reduce the CPU I/O by reading a particular value of a Filtered Index.</li>
<li>The Filtered index stores only keys and reference of data.</li>
<li>Once you create a Filtered Index on the PartitionScheme, you have to create same Filtered Index for every new table partitions which create a problem because a combination of Filtered indexes may contain the different value.</li>
<li>If you already apply table partition, you should not apply filtered indexes on those partitions.</li>
</ul>
<p><strong>Table Partition:</strong></p>
<ul>
<li>The Table Partitioning breaks your main table into small groups of tables based on defined partitioning key.<br />
The data physically divided for better management and fast retrieval.</li>
<li>For example, you have a 20GB of a table, and it contains total 5 years of data so you can partition your table base on years which will create five table partitions with each size of 4GB.</li>
<li>To implement Table partitioning, you need to create .ndf files for each partition, partition function, partition scheme.</li>
<li>It stores all columns of your table in partitions; it is not just storing the key of data like Filtered Index.<br />
You can define indexes on each table partitions.</li>
<li>The maintenance of Table Partitions is costly and time taking.</li>
</ul>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server: Create index on large Temp Tables</title>
		<link>https://www.dbrnd.com/2017/02/sql-server-create-index-on-large-temp-tables-clustered-non-clustered-index/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sun, 26 Feb 2017 16:16:02 +0000</pubDate>
				<category><![CDATA[SQL Server Interview]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[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 Tuning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[Temp db Performance]]></category>
		<category><![CDATA[Temp Table]]></category>
		<category><![CDATA[TempDB]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4198</guid>

					<description><![CDATA[I have given one assignment to a database developer team for preparing general database development practices. I have found one point in that document: &#8220;Do not create Indexes on Temp Tables&#8221;. The use of Temp Tables is very common in SQL Server. Most of the SQL database developers are storing their data into temp tables. [&#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-create-index-on-large-temp-tables-clustered-non-clustered-index%2F&amp;linkname=SQL%20Server%3A%20Create%20index%20on%20large%20Temp%20Tables" 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-create-index-on-large-temp-tables-clustered-non-clustered-index%2F&amp;linkname=SQL%20Server%3A%20Create%20index%20on%20large%20Temp%20Tables" 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-create-index-on-large-temp-tables-clustered-non-clustered-index%2F&amp;linkname=SQL%20Server%3A%20Create%20index%20on%20large%20Temp%20Tables" 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-create-index-on-large-temp-tables-clustered-non-clustered-index%2F&amp;linkname=SQL%20Server%3A%20Create%20index%20on%20large%20Temp%20Tables" 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-create-index-on-large-temp-tables-clustered-non-clustered-index%2F&amp;linkname=SQL%20Server%3A%20Create%20index%20on%20large%20Temp%20Tables" 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-create-index-on-large-temp-tables-clustered-non-clustered-index%2F&amp;linkname=SQL%20Server%3A%20Create%20index%20on%20large%20Temp%20Tables" 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-create-index-on-large-temp-tables-clustered-non-clustered-index%2F&#038;title=SQL%20Server%3A%20Create%20index%20on%20large%20Temp%20Tables" data-a2a-url="https://www.dbrnd.com/2017/02/sql-server-create-index-on-large-temp-tables-clustered-non-clustered-index/" data-a2a-title="SQL Server: Create index on large Temp Tables"></a></p><p><em>I have given one assignment to a database developer team for preparing general database development practices.<br />
I have found one point in that document: &#8220;Do not create Indexes on Temp Tables&#8221;.</em></p>
<p>The use of Temp Tables is very common in SQL Server. Most of the SQL database developers are storing their data into temp tables.<br />
Let me, explore something about, the best practices of Temp Tables. </p>
<blockquote><p>In general advice, we should avoid the use of temp tables because it requires more CPU/IO while accessing the TempDB.<br />
When you are storing data into temp tables, it stores in TempDB files means the physical disk operation is involved.</p></blockquote>
<blockquote><p>Like any other regular table, temp table also requires disk space to store temporary data and other resources for manipulation.</p></blockquote>
<blockquote><p>I have seen that many developers are saving a significant number of records in Temp Tables and they are not thinking even for Indexing on Temp Tables.</p></blockquote>
<blockquote><p>If you don&#8217;t know, please note: You can create a Clustered and Non-Clustered Indexes on Temp Tables which improves your query performance.</p></blockquote>
<blockquote><p>Again, more indexes will create more problems because it needs space and manipulation.<br />
First, you should analyze the volume of data, execution plan and accordingly you should apply indexes on Temp tables.</p></blockquote>
<blockquote><p>Personally, I have checked the performance of Temp Tables with Clustered Index, which is much better than Temp Table without an Indexes. </p></blockquote>
<p><em>I am rejecting all comments and points which say that &#8221; we should not apply Indexes on Temp Tables. &#8220;</em></p>
<blockquote class="wp-embedded-content" data-secret="BbyB9dqjyi"><p><a href="https://www.dbrnd.com/2016/02/sql-server-difference-between-temporary-table-and-table-variable/">SQL Server: Difference between Temporary Table and Table Variable</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/02/sql-server-difference-between-temporary-table-and-table-variable/embed/#?secret=BbyB9dqjyi" data-secret="BbyB9dqjyi" width="600" height="338" title="&#8220;SQL Server: Difference between Temporary Table and Table Variable&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
]]></content:encoded>
					
		
		
			</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>PostgreSQL: Rebuild all Indexes using REINDEXDB utility and REINDEX command</title>
		<link>https://www.dbrnd.com/2017/01/postgresql-rebuild-all-indexes-using-reindexdb-utility-and-reindex-command-remove-fragmentation-improve-performance/</link>
					<comments>https://www.dbrnd.com/2017/01/postgresql-rebuild-all-indexes-using-reindexdb-utility-and-reindex-command-remove-fragmentation-improve-performance/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 05 Jan 2017 18:34:36 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[Rebuild Index]]></category>
		<category><![CDATA[reindex]]></category>
		<category><![CDATA[reindexdb]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3645</guid>

					<description><![CDATA[The Index Rebuilding is a very common and routine task for a Database Administrator. All types of RDBMS system have various types of Reindexing option. The Index Rebuilding is necessary periodically to remove fragmentation of Indexes. PostgreSQL provides two ways to perform Reindexing on Database. Using REINDEX command: You can execute REINDEX command on Database, [&#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%2Fpostgresql-rebuild-all-indexes-using-reindexdb-utility-and-reindex-command-remove-fragmentation-improve-performance%2F&amp;linkname=PostgreSQL%3A%20Rebuild%20all%20Indexes%20using%20REINDEXDB%20utility%20and%20REINDEX%20command" 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%2Fpostgresql-rebuild-all-indexes-using-reindexdb-utility-and-reindex-command-remove-fragmentation-improve-performance%2F&amp;linkname=PostgreSQL%3A%20Rebuild%20all%20Indexes%20using%20REINDEXDB%20utility%20and%20REINDEX%20command" 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%2Fpostgresql-rebuild-all-indexes-using-reindexdb-utility-and-reindex-command-remove-fragmentation-improve-performance%2F&amp;linkname=PostgreSQL%3A%20Rebuild%20all%20Indexes%20using%20REINDEXDB%20utility%20and%20REINDEX%20command" 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%2Fpostgresql-rebuild-all-indexes-using-reindexdb-utility-and-reindex-command-remove-fragmentation-improve-performance%2F&amp;linkname=PostgreSQL%3A%20Rebuild%20all%20Indexes%20using%20REINDEXDB%20utility%20and%20REINDEX%20command" 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%2Fpostgresql-rebuild-all-indexes-using-reindexdb-utility-and-reindex-command-remove-fragmentation-improve-performance%2F&amp;linkname=PostgreSQL%3A%20Rebuild%20all%20Indexes%20using%20REINDEXDB%20utility%20and%20REINDEX%20command" 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%2Fpostgresql-rebuild-all-indexes-using-reindexdb-utility-and-reindex-command-remove-fragmentation-improve-performance%2F&amp;linkname=PostgreSQL%3A%20Rebuild%20all%20Indexes%20using%20REINDEXDB%20utility%20and%20REINDEX%20command" 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%2Fpostgresql-rebuild-all-indexes-using-reindexdb-utility-and-reindex-command-remove-fragmentation-improve-performance%2F&#038;title=PostgreSQL%3A%20Rebuild%20all%20Indexes%20using%20REINDEXDB%20utility%20and%20REINDEX%20command" data-a2a-url="https://www.dbrnd.com/2017/01/postgresql-rebuild-all-indexes-using-reindexdb-utility-and-reindex-command-remove-fragmentation-improve-performance/" data-a2a-title="PostgreSQL: Rebuild all Indexes using REINDEXDB utility and REINDEX command"></a></p><p>The Index Rebuilding is a very common and routine task for a Database Administrator. </p>
<blockquote><p>All types of RDBMS system have various types of Reindexing option.<br />
The Index Rebuilding is necessary periodically to remove fragmentation of Indexes. </p></blockquote>
<p>PostgreSQL provides two ways to perform Reindexing on Database.</p>
<p><strong>Using REINDEX command:</strong></p>
<blockquote><p>You can execute REINDEX command on Database, Table and Index.<br />
You can connect PostgreSQL using PGAdmin or PSQL tools to execute this command. </p></blockquote>
<p><strong>Reindex all indexes of Database:</strong></p>
<pre class="crayon-plain-tag">REINDEX DATABASE Database_Name;</pre> </p>
<p><strong>Reindex on particular Index:</strong></p>
<pre class="crayon-plain-tag">REINDEX INDEX Index_Name;</pre> </p>
<p><strong>Reindex on particular Table:</strong></p>
<pre class="crayon-plain-tag">REINDEX TABLE Table_Name;</pre> </p>
<p><strong>Using REINDEXDB.EXE utility:</strong></p>
<blockquote><p>A REINDEXDB is a one type of utility of PostgreSQL. It is an executable file which we can run without connect to database server.</p></blockquote>
<blockquote><p>A REINDEXDB requires command line arguments like database_username, database_name.<br />
We can execute REINDEXDB using command prompt of the Operating System. </p></blockquote>
<p>Below an example of Windows Command Prompt, the same way you can also execute in Linux.</p>
<p><strong>Reindex all Database of PostgreSQL Server:</strong></p>
<pre class="crayon-plain-tag">C:\Program Files\PostgreSQL\9.5\bin&gt; reindexdb.exe -U user_name -a
Password:****</pre> </p>
<p><strong>Reindex on particular Database:</strong></p>
<pre class="crayon-plain-tag">C:\Program Files\PostgreSQL\9.5\bin&gt; reindexdb.exe -d database -U user_name
Password:****</pre> </p>
<p><strong>Reindex on particular Table:</strong></p>
<pre class="crayon-plain-tag">C:\Program Files\PostgreSQL\9.5\bin&gt; reindexdb.exe -d database_name -U user_name -t table_name
Password:****</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2017/01/postgresql-rebuild-all-indexes-using-reindexdb-utility-and-reindex-command-remove-fragmentation-improve-performance/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
