<?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>Reorganize Index &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/reorganize-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, 27 Feb 2017 20:12:24 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.4</generator>
	<item>
		<title>SQL Server: T-SQL Script to Rebuild all Indexes of a Database</title>
		<link>https://www.dbrnd.com/2016/10/sql-server-t-sql-script-to-rebuild-all-indexes-of-a-database-remove-index-fragmentation-require-exclusive-lock/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sat, 29 Oct 2016 16:16:12 +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[fragmentation]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[Rebuild Index]]></category>
		<category><![CDATA[Reorganize 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=3633</guid>

					<description><![CDATA[In this post, I am sharing SQL Server Database Administrator script for rebuilding all Indexes of a Database. To Rebuild or Reorganize the Indexes is a very common task for DBA. If Index fragmentation is increasing, periodically it requires executing Rebuild Index for better performance. If we want to Rebuild all Indexes of a 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%2F2016%2F10%2Fsql-server-t-sql-script-to-rebuild-all-indexes-of-a-database-remove-index-fragmentation-require-exclusive-lock%2F&amp;linkname=SQL%20Server%3A%20T-SQL%20Script%20to%20Rebuild%20all%20Indexes%20of%20a%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%2F2016%2F10%2Fsql-server-t-sql-script-to-rebuild-all-indexes-of-a-database-remove-index-fragmentation-require-exclusive-lock%2F&amp;linkname=SQL%20Server%3A%20T-SQL%20Script%20to%20Rebuild%20all%20Indexes%20of%20a%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%2F2016%2F10%2Fsql-server-t-sql-script-to-rebuild-all-indexes-of-a-database-remove-index-fragmentation-require-exclusive-lock%2F&amp;linkname=SQL%20Server%3A%20T-SQL%20Script%20to%20Rebuild%20all%20Indexes%20of%20a%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%2F2016%2F10%2Fsql-server-t-sql-script-to-rebuild-all-indexes-of-a-database-remove-index-fragmentation-require-exclusive-lock%2F&amp;linkname=SQL%20Server%3A%20T-SQL%20Script%20to%20Rebuild%20all%20Indexes%20of%20a%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%2F2016%2F10%2Fsql-server-t-sql-script-to-rebuild-all-indexes-of-a-database-remove-index-fragmentation-require-exclusive-lock%2F&amp;linkname=SQL%20Server%3A%20T-SQL%20Script%20to%20Rebuild%20all%20Indexes%20of%20a%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%2F2016%2F10%2Fsql-server-t-sql-script-to-rebuild-all-indexes-of-a-database-remove-index-fragmentation-require-exclusive-lock%2F&amp;linkname=SQL%20Server%3A%20T-SQL%20Script%20to%20Rebuild%20all%20Indexes%20of%20a%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%2F2016%2F10%2Fsql-server-t-sql-script-to-rebuild-all-indexes-of-a-database-remove-index-fragmentation-require-exclusive-lock%2F&#038;title=SQL%20Server%3A%20T-SQL%20Script%20to%20Rebuild%20all%20Indexes%20of%20a%20Database" data-a2a-url="https://www.dbrnd.com/2016/10/sql-server-t-sql-script-to-rebuild-all-indexes-of-a-database-remove-index-fragmentation-require-exclusive-lock/" data-a2a-title="SQL Server: T-SQL Script to Rebuild all Indexes of a Database"></a></p><p>In this post, I am sharing SQL Server Database Administrator script for rebuilding all Indexes of a Database. </p>
<blockquote><p>To Rebuild or Reorganize the Indexes is a very common task for DBA.<br />
If Index fragmentation is increasing, periodically it requires executing Rebuild Index for better performance.</p></blockquote>
<blockquote><p>If we want to Rebuild all Indexes of a Database, we should build and generate the script because using default command we can only perform Rebuild operation on table level.</p></blockquote>
<blockquote data-secret="uWF28NbyO9" class="wp-embedded-content"><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 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=uWF28NbyO9" data-secret="uWF28NbyO9" 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>
<p>In below script, I commented Fill Factor related changes, and If anyone wants, they uncomment it.<br />
Please SELECT your database and execute the below script.</p>
<blockquote><p><strong>Note:</strong> Database <a href="https://msdn.microsoft.com/en-us/library/ms189858.aspx" target="_blank"><strong>REBUILD INDEX</strong></a> is a very costly operation and It requires an exclusive lock on table so please aware yourself before executing it.</p></blockquote>
<pre class="crayon-plain-tag">DECLARE @DatabaseName SYSNAME   = DB_NAME()
DECLARE @TableName VARCHAR(256) 
--DECLARE @FILLFACTOR INT = 85
DECLARE @SQL NVARCHAR(MAX) =

 'DECLARE curAllIndex CURSOR FOR SELECT TABLE_SCHEMA +
 ''.'' + TABLE_NAME AS TABLENAME  
 FROM ' + @DatabaseName + '.INFORMATION_SCHEMA.TABLES WHERE
 TABLE_TYPE = ''BASE TABLE'''  
 
BEGIN 
  EXEC sp_executeSQL @SQL  
  OPEN curAllIndex
  FETCH NEXT FROM curAllIndex INTO @TableName  
  WHILE (@@FETCH_STATUS = 0) 
  BEGIN  
       /* -- For using FillFactor setting. 
	   SET @DynamicSQL = 'ALTER INDEX ALL ON ' + @TableName +  
	   ' REBUILD WITH (FILLFACTOR = ' + CONVERT(VARCHAR,@FILLFACTOR) + ')' 
	   */
	   SET @SQL = 'ALTER INDEX ALL ON ' + @TableName +  
	   ' REBUILD ' 
       PRINT @SQL       
       EXEC sp_executeSQL @SQL 
       FETCH NEXT FROM curAllIndex INTO @TableName  
   END   
   CLOSE curAllIndex  
   DEALLOCATE curAllIndex 
END</pre> </p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
