<?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>Shrink Database &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/shrink-database/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, 15 May 2017 19:01:54 +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: Why Shrink Database is bad, Check the practical demonstration</title>
		<link>https://www.dbrnd.com/2017/05/sql-server-why-shrink-database-is-bad-check-the-practical-demonstration-fragmentation/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 25 May 2017 16:16:03 +0000</pubDate>
				<category><![CDATA[SQL Server]]></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[Shrink Database]]></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=5329</guid>

					<description><![CDATA[Few of SQL Server DBAs are frequently executing Shrink on database or data files. Why? because they are gaining more free space after shrink. You can find N number of theory on, why you should not shrink your database or data file in SQL Server? Instead of big theory, I am sharing full practical demonstration [&#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-why-shrink-database-is-bad-check-the-practical-demonstration-fragmentation%2F&amp;linkname=SQL%20Server%3A%20Why%20Shrink%20Database%20is%20bad%2C%20Check%20the%20practical%20demonstration" 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-why-shrink-database-is-bad-check-the-practical-demonstration-fragmentation%2F&amp;linkname=SQL%20Server%3A%20Why%20Shrink%20Database%20is%20bad%2C%20Check%20the%20practical%20demonstration" 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-why-shrink-database-is-bad-check-the-practical-demonstration-fragmentation%2F&amp;linkname=SQL%20Server%3A%20Why%20Shrink%20Database%20is%20bad%2C%20Check%20the%20practical%20demonstration" 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-why-shrink-database-is-bad-check-the-practical-demonstration-fragmentation%2F&amp;linkname=SQL%20Server%3A%20Why%20Shrink%20Database%20is%20bad%2C%20Check%20the%20practical%20demonstration" 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-why-shrink-database-is-bad-check-the-practical-demonstration-fragmentation%2F&amp;linkname=SQL%20Server%3A%20Why%20Shrink%20Database%20is%20bad%2C%20Check%20the%20practical%20demonstration" 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-why-shrink-database-is-bad-check-the-practical-demonstration-fragmentation%2F&amp;linkname=SQL%20Server%3A%20Why%20Shrink%20Database%20is%20bad%2C%20Check%20the%20practical%20demonstration" 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-why-shrink-database-is-bad-check-the-practical-demonstration-fragmentation%2F&#038;title=SQL%20Server%3A%20Why%20Shrink%20Database%20is%20bad%2C%20Check%20the%20practical%20demonstration" data-a2a-url="https://www.dbrnd.com/2017/05/sql-server-why-shrink-database-is-bad-check-the-practical-demonstration-fragmentation/" data-a2a-title="SQL Server: Why Shrink Database is bad, Check the practical demonstration"></a></p><p>Few of SQL Server DBAs are frequently executing Shrink on database or data files. Why? because they are gaining more free space after shrink. </p>
<p>You can find N number of theory on, why you should not shrink your database or data file in SQL Server?</p>
<blockquote><p>Instead of big theory, I am sharing full practical demonstration on this. You should not shrink your database or data files otherwise it generates massive fragmentation for your tables and indexes. Still, you can shrink your log file, but after full backup only. </p></blockquote>
<p><strong>Create a test database and use it:</strong></p>
<pre class="crayon-plain-tag">CREATE DATABASE Test_Shrink
GO

Use Test_Shrink
GO</pre> </p>
<p><strong>Create a sample table:</strong></p>
<pre class="crayon-plain-tag">CREATE DATABASE Test_Shrink
GO

Use Test_Shrink
GO</pre> </p>
<p><strong>Create second sample table with clustered index:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_test2
(
    id INT IDENTITY(1,1)
    ,tag CHAR (7000) DEFAULT 'dbrnd'
)
GO
CREATE CLUSTERED INDEX pk_test2 ON tbl_test2 (id);
GO</pre> </p>
<p><strong>Insert few sample records in both the tables:</strong></p>
<pre class="crayon-plain-tag">INSERT INTO tbl_test1 DEFAULT VALUES;
GO 1500
 
INSERT INTO tbl_test2 DEFAULT VALUES;
GO 1500</pre> </p>
<p><strong>Check the average fragmentation of Index:</strong></p>
<pre class="crayon-plain-tag">SELECT
    [avg_fragmentation_in_percent]
FROM sys.dm_db_index_physical_stats 
(
    DB_ID (N'Test_Shrink'), OBJECT_ID (N'tbl_test2'), 1, NULL, 'LIMITED'
)
GO

--The result is:
--0.33%</pre> </p>
<p><strong>Drop one sample table to test Shrink:</strong></p>
<pre class="crayon-plain-tag">DROP TABLE tbl_test1;
GO</pre> </p>
<p><strong>Shrink your database:</strong></p>
<pre class="crayon-plain-tag">DBCC SHRINKDATABASE (Test_Shrink);
GO</pre> </p>
<p><strong>Check the fragmentation of index:</strong><br />
You can find below result like 99.6% fragmentation for Index. Before shrink database, it was just 0.33%.</p>
<pre class="crayon-plain-tag">SELECT
    [avg_fragmentation_in_percent]
FROM sys.dm_db_index_physical_stats 
(
    DB_ID (N'Test_Shrink'), OBJECT_ID (N'tbl_test2'), 1, NULL, 'LIMITED'
)
GO

--The result is:
--99.6%</pre> </p>
<p><strong>Now, REBUILD your index to remove the fragmentation:</strong></p>
<pre class="crayon-plain-tag">ALTER INDEX pk_test2 ON tbl_test2 REBUILD
GO</pre> </p>
<p><strong>Check the fragmentation of index:</strong></p>
<pre class="crayon-plain-tag">SELECT
    [avg_fragmentation_in_percent]
FROM sys.dm_db_index_physical_stats 
(
    DB_ID (N'Test_Shrink'), OBJECT_ID (N'tbl_test2'), 1, NULL, 'LIMITED'
)
GO

--The result is:
-- 0%</pre> </p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
