<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; Shrinking NDF and MDF Files &#8211; A Safe Operation</title>
	<atom:link href="http://blog.sqlauthority.com/2009/01/25/sql-server-shrinking-ndf-and-mdf-files-a-safe-operation/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2009/01/25/sql-server-shrinking-ndf-and-mdf-files-a-safe-operation/</link>
	<description>Personal Notes of Pinal Dave</description>
	<lastBuildDate>Sun, 12 Feb 2012 09:22:39 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Mariyappan</title>
		<link>http://blog.sqlauthority.com/2009/01/25/sql-server-shrinking-ndf-and-mdf-files-a-safe-operation/#comment-227315</link>
		<dc:creator><![CDATA[Mariyappan]]></dc:creator>
		<pubDate>Wed, 28 Dec 2011 10:10:09 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2118#comment-227315</guid>
		<description><![CDATA[My Sql Server 2000 Data base Ndf file have 45 gb.Is it possible to reduce witout risk.]]></description>
		<content:encoded><![CDATA[<p>My Sql Server 2000 Data base Ndf file have 45 gb.Is it possible to reduce witout risk.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Subba</title>
		<link>http://blog.sqlauthority.com/2009/01/25/sql-server-shrinking-ndf-and-mdf-files-a-safe-operation/#comment-213550</link>
		<dc:creator><![CDATA[Subba]]></dc:creator>
		<pubDate>Thu, 08 Dec 2011 17:25:50 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2118#comment-213550</guid>
		<description><![CDATA[Thanks Imran for your elaborated explanation on shrinking. Thanks lot]]></description>
		<content:encoded><![CDATA[<p>Thanks Imran for your elaborated explanation on shrinking. Thanks lot</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vikas</title>
		<link>http://blog.sqlauthority.com/2009/01/25/sql-server-shrinking-ndf-and-mdf-files-a-safe-operation/#comment-196833</link>
		<dc:creator><![CDATA[vikas]]></dc:creator>
		<pubDate>Wed, 16 Nov 2011 12:06:14 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2118#comment-196833</guid>
		<description><![CDATA[Hi,
Is there any query to find out the initial size of database when it was created?]]></description>
		<content:encoded><![CDATA[<p>Hi,<br />
Is there any query to find out the initial size of database when it was created?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aashish Vaghela</title>
		<link>http://blog.sqlauthority.com/2009/01/25/sql-server-shrinking-ndf-and-mdf-files-a-safe-operation/#comment-148329</link>
		<dc:creator><![CDATA[Aashish Vaghela]]></dc:creator>
		<pubDate>Thu, 14 Jul 2011 19:47:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2118#comment-148329</guid>
		<description><![CDATA[Kiran,
As long as I understand, the BAK file actually backs up the Database &amp; not individual files. Therefore whether MDF or LDF they are the part of the same DB. Hence I doubt that would be actually possible, unless you can come across some specific utility on the internet which can just extract the MDF &amp; not the LDF out of the BAK file. 

If I were in your position, I would rather restore that BAK file on a medium where there is lot of 
space available.]]></description>
		<content:encoded><![CDATA[<p>Kiran,<br />
As long as I understand, the BAK file actually backs up the Database &amp; not individual files. Therefore whether MDF or LDF they are the part of the same DB. Hence I doubt that would be actually possible, unless you can come across some specific utility on the internet which can just extract the MDF &amp; not the LDF out of the BAK file. </p>
<p>If I were in your position, I would rather restore that BAK file on a medium where there is lot of<br />
space available.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kiran</title>
		<link>http://blog.sqlauthority.com/2009/01/25/sql-server-shrinking-ndf-and-mdf-files-a-safe-operation/#comment-148195</link>
		<dc:creator><![CDATA[kiran]]></dc:creator>
		<pubDate>Thu, 14 Jul 2011 06:52:07 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2118#comment-148195</guid>
		<description><![CDATA[Hi,

Is there any possibility of restoring a .bak file without .ldf...I mean to say .bak file containing .mdf and .ldf due to space constraint is it possible to restore only .mdf..]]></description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>Is there any possibility of restoring a .bak file without .ldf&#8230;I mean to say .bak file containing .mdf and .ldf due to space constraint is it possible to restore only .mdf..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mangesh</title>
		<link>http://blog.sqlauthority.com/2009/01/25/sql-server-shrinking-ndf-and-mdf-files-a-safe-operation/#comment-137322</link>
		<dc:creator><![CDATA[Mangesh]]></dc:creator>
		<pubDate>Sun, 29 May 2011 05:42:34 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2118#comment-137322</guid>
		<description><![CDATA[hi all,

how much .ndf files create in one database?

Regards,
Mangesh]]></description>
		<content:encoded><![CDATA[<p>hi all,</p>
<p>how much .ndf files create in one database?</p>
<p>Regards,<br />
Mangesh</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dba</title>
		<link>http://blog.sqlauthority.com/2009/01/25/sql-server-shrinking-ndf-and-mdf-files-a-safe-operation/#comment-102258</link>
		<dc:creator><![CDATA[dba]]></dc:creator>
		<pubDate>Fri, 26 Nov 2010 07:54:50 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2118#comment-102258</guid>
		<description><![CDATA[Hello Pinal dev,

How can we check , wehther the data presnt or not in the files?]]></description>
		<content:encoded><![CDATA[<p>Hello Pinal dev,</p>
<p>How can we check , wehther the data presnt or not in the files?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aashish Vaghela</title>
		<link>http://blog.sqlauthority.com/2009/01/25/sql-server-shrinking-ndf-and-mdf-files-a-safe-operation/#comment-89409</link>
		<dc:creator><![CDATA[Aashish Vaghela]]></dc:creator>
		<pubDate>Sat, 25 Sep 2010 14:38:49 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2118#comment-89409</guid>
		<description><![CDATA[Thanks Brutus !

One more thing that I added to your script above was 

DBCC UpdateUsage(MyDBName)           &amp;&amp;  

SP_UpdateStats


However, my 2nd question on July 28th, 12:46am still remains ? Any idea of Automating this process of monitoring &amp; truncating the DB LOG (.ldf) file ... ? Is is possible to set some TRIGGER to monitor the LOG Size &amp; the moment it grows beyond a certain pre-defined limit, it gets truncated &amp; the DB is Shrunk .... ?

See if you can share some insight on to this part ??]]></description>
		<content:encoded><![CDATA[<p>Thanks Brutus !</p>
<p>One more thing that I added to your script above was </p>
<p>DBCC UpdateUsage(MyDBName)           &amp;&amp;  </p>
<p>SP_UpdateStats</p>
<p>However, my 2nd question on July 28th, 12:46am still remains ? Any idea of Automating this process of monitoring &amp; truncating the DB LOG (.ldf) file &#8230; ? Is is possible to set some TRIGGER to monitor the LOG Size &amp; the moment it grows beyond a certain pre-defined limit, it gets truncated &amp; the DB is Shrunk &#8230;. ?</p>
<p>See if you can share some insight on to this part ??</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: hardtoget410</title>
		<link>http://blog.sqlauthority.com/2009/01/25/sql-server-shrinking-ndf-and-mdf-files-a-safe-operation/#comment-89379</link>
		<dc:creator><![CDATA[hardtoget410]]></dc:creator>
		<pubDate>Sat, 25 Sep 2010 10:09:42 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2118#comment-89379</guid>
		<description><![CDATA[Dear All please i want to know how to restore database after it has been overwritten by backing up restore.My case is as follows I have restored my database from old backup by I restored this database by mistake on last data base updated so it overwritten this updated database.so please tell me how to restore my original database before it&#039;s overwritten.]]></description>
		<content:encoded><![CDATA[<p>Dear All please i want to know how to restore database after it has been overwritten by backing up restore.My case is as follows I have restored my database from old backup by I restored this database by mistake on last data base updated so it overwritten this updated database.so please tell me how to restore my original database before it&#8217;s overwritten.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: brutus</title>
		<link>http://blog.sqlauthority.com/2009/01/25/sql-server-shrinking-ndf-and-mdf-files-a-safe-operation/#comment-89090</link>
		<dc:creator><![CDATA[brutus]]></dc:creator>
		<pubDate>Thu, 23 Sep 2010 10:03:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2118#comment-89090</guid>
		<description><![CDATA[hi guys...as a lot of information exist on the saint internet i summarize this for shrinking the log file:
--first we backup the transaction log 
go
BACKUP LOG [database name] TO 
 DISK = &#039;d:\temp\aa.log&#039; WITH NOFORMAT, NOINIT,  
 NAME = N&#039;databasename-Transaction Log  Backup&#039;, SKIP, NOREWIND, NOUNLOAD,  
 STATS = 10
GO

--find the name for the log file
use database
select  name,physical_name from sys.database_files

--change the recovery model in order to shrink the database...otherwise it will not work...

ALTER DATABASE [databasename] SET RECOVERY Simple
WITH NO_WAIT
GO
--shrink the log file 
DBCC SHRINKFILE (N&#039;name of the log file&#039; , 50)
GO

ALTER DATABASE [databasename] SET RECOVERY FULL 

--rebuild index...

if this operation is done in the evening when nobody works it would be great:)]]></description>
		<content:encoded><![CDATA[<p>hi guys&#8230;as a lot of information exist on the saint internet i summarize this for shrinking the log file:<br />
&#8211;first we backup the transaction log<br />
go<br />
BACKUP LOG [database name] TO<br />
 DISK = &#8216;d:\temp\aa.log&#8217; WITH NOFORMAT, NOINIT,<br />
 NAME = N&#8217;databasename-Transaction Log  Backup&#8217;, SKIP, NOREWIND, NOUNLOAD,<br />
 STATS = 10<br />
GO</p>
<p>&#8211;find the name for the log file<br />
use database<br />
select  name,physical_name from sys.database_files</p>
<p>&#8211;change the recovery model in order to shrink the database&#8230;otherwise it will not work&#8230;</p>
<p>ALTER DATABASE [databasename] SET RECOVERY Simple<br />
WITH NO_WAIT<br />
GO<br />
&#8211;shrink the log file<br />
DBCC SHRINKFILE (N&#8217;name of the log file&#8217; , 50)<br />
GO</p>
<p>ALTER DATABASE [databasename] SET RECOVERY FULL </p>
<p>&#8211;rebuild index&#8230;</p>
<p>if this operation is done in the evening when nobody works it would be great:)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aashish Vaghela</title>
		<link>http://blog.sqlauthority.com/2009/01/25/sql-server-shrinking-ndf-and-mdf-files-a-safe-operation/#comment-81894</link>
		<dc:creator><![CDATA[Aashish Vaghela]]></dc:creator>
		<pubDate>Tue, 27 Jul 2010 19:16:20 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2118#comment-81894</guid>
		<description><![CDATA[Hello Pinal,

One more thing, in reference to the request above.
Is there a way we can use OSQL (SQL 2000) or SQLCMD based scripts to accomplish this task of monitoring the LOG file.

I&#039;m planning to create a simple DOS BATch file to perform such a task. If regular DOS BAT file isn&#039;t going to be sufficient, then probably we can think of creating a VBScript file to do the same. What do you say ??

Regards,
Aashish. Vaghela]]></description>
		<content:encoded><![CDATA[<p>Hello Pinal,</p>
<p>One more thing, in reference to the request above.<br />
Is there a way we can use OSQL (SQL 2000) or SQLCMD based scripts to accomplish this task of monitoring the LOG file.</p>
<p>I&#8217;m planning to create a simple DOS BATch file to perform such a task. If regular DOS BAT file isn&#8217;t going to be sufficient, then probably we can think of creating a VBScript file to do the same. What do you say ??</p>
<p>Regards,<br />
Aashish. Vaghela</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aashish Vaghela</title>
		<link>http://blog.sqlauthority.com/2009/01/25/sql-server-shrinking-ndf-and-mdf-files-a-safe-operation/#comment-81890</link>
		<dc:creator><![CDATA[Aashish Vaghela]]></dc:creator>
		<pubDate>Tue, 27 Jul 2010 18:42:23 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2118#comment-81890</guid>
		<description><![CDATA[Hello Pinal,

Once again, looks like I&#039;m running into some sorts of trouble
keeping the LDF Log file under check. I was wondering if I can
automate the process by some trigger. This trigger can fire, at a specific time whenever the size of the LOG file exceeds a particular value in MB. Lets say if the size of the LOG file (.LDF) reaches 100MB, it should be auto-truncated.

Can this be achieved...?? I think so. However, I&#039;m not much of a T-SQL Programmer. So, I&#039;d definitely appreciate if I can get help on such a TRIGGER.

Thanks.

Aashish. Vaghela]]></description>
		<content:encoded><![CDATA[<p>Hello Pinal,</p>
<p>Once again, looks like I&#8217;m running into some sorts of trouble<br />
keeping the LDF Log file under check. I was wondering if I can<br />
automate the process by some trigger. This trigger can fire, at a specific time whenever the size of the LOG file exceeds a particular value in MB. Lets say if the size of the LOG file (.LDF) reaches 100MB, it should be auto-truncated.</p>
<p>Can this be achieved&#8230;?? I think so. However, I&#8217;m not much of a T-SQL Programmer. So, I&#8217;d definitely appreciate if I can get help on such a TRIGGER.</p>
<p>Thanks.</p>
<p>Aashish. Vaghela</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: hariom vats</title>
		<link>http://blog.sqlauthority.com/2009/01/25/sql-server-shrinking-ndf-and-mdf-files-a-safe-operation/#comment-77238</link>
		<dc:creator><![CDATA[hariom vats]]></dc:creator>
		<pubDate>Tue, 22 Jun 2010 05:30:55 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2118#comment-77238</guid>
		<description><![CDATA[sir,

i go through your blog.and i use  


USE DatabaseName
GO
DBCC SHRINKFILE(, 100)
My log file size was 38 gb after this command it is 34 gb.

while it should be 100mb.

do the needfull for further steps]]></description>
		<content:encoded><![CDATA[<p>sir,</p>
<p>i go through your blog.and i use  </p>
<p>USE DatabaseName<br />
GO<br />
DBCC SHRINKFILE(, 100)<br />
My log file size was 38 gb after this command it is 34 gb.</p>
<p>while it should be 100mb.</p>
<p>do the needfull for further steps</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: calin</title>
		<link>http://blog.sqlauthority.com/2009/01/25/sql-server-shrinking-ndf-and-mdf-files-a-safe-operation/#comment-76290</link>
		<dc:creator><![CDATA[calin]]></dc:creator>
		<pubDate>Tue, 15 Jun 2010 07:15:07 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2118#comment-76290</guid>
		<description><![CDATA[Hello there.

It is more than mdf and ldf. 

First of all, let&#039;s discuss the shrinking of data files (data means mdf and ndf). You will encounter two different methods, that use the same mechanism internally: DBCC SHRINKFILE, DBCC SHRINKDATABASE.
Let me give you and example that actually happened a while ago to a customer: they were scripting a database, so we ended up having a database that was defined as having 100 GB data file (only one data file), but with no data in it. Because the customer wanted to save space, we tried to shrink the database by using DBCC SHRINKDATABASE. It had no effect whatsoever, because you cannot go lower than the initial definition of the database (100 GB in our case). By using DBCCSHRINKFILE we could actually modify the data file to a lower value, so the database size was lowered.

Second of all, for the log files (ldf). A transaction log file has a different structure and behavior compared to a data file. Every now and then, some portion of the transaction log is marked as &quot;not needed anymore&quot;, so it can be overwritten. This is called truncation. It simply tells SQL Server that there is space within transaction log that can be reused. If you need to recover that space and give it back to the OS, you can only do that after the log is truncated (which, in turn, relates to recovery model and whether you have taken a backup or not). 

I do apologize for making it a bit too technical.

best regards,
calin]]></description>
		<content:encoded><![CDATA[<p>Hello there.</p>
<p>It is more than mdf and ldf. </p>
<p>First of all, let&#8217;s discuss the shrinking of data files (data means mdf and ndf). You will encounter two different methods, that use the same mechanism internally: DBCC SHRINKFILE, DBCC SHRINKDATABASE.<br />
Let me give you and example that actually happened a while ago to a customer: they were scripting a database, so we ended up having a database that was defined as having 100 GB data file (only one data file), but with no data in it. Because the customer wanted to save space, we tried to shrink the database by using DBCC SHRINKDATABASE. It had no effect whatsoever, because you cannot go lower than the initial definition of the database (100 GB in our case). By using DBCCSHRINKFILE we could actually modify the data file to a lower value, so the database size was lowered.</p>
<p>Second of all, for the log files (ldf). A transaction log file has a different structure and behavior compared to a data file. Every now and then, some portion of the transaction log is marked as &#8220;not needed anymore&#8221;, so it can be overwritten. This is called truncation. It simply tells SQL Server that there is space within transaction log that can be reused. If you need to recover that space and give it back to the OS, you can only do that after the log is truncated (which, in turn, relates to recovery model and whether you have taken a backup or not). </p>
<p>I do apologize for making it a bit too technical.</p>
<p>best regards,<br />
calin</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: calin</title>
		<link>http://blog.sqlauthority.com/2009/01/25/sql-server-shrinking-ndf-and-mdf-files-a-safe-operation/#comment-76286</link>
		<dc:creator><![CDATA[calin]]></dc:creator>
		<pubDate>Tue, 15 Jun 2010 06:51:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2118#comment-76286</guid>
		<description><![CDATA[Hello there.

With all due respect, this seems to be a case where proper database sizing was not made since the very beginning. What you can do, and this is just my two cents, is to monitor the growth of your DB over time, and start from there. I&#039;m pretty sure that you&#039;ll need to add additional disks if moving historical data to a data warehouse is not an option.

best regards,
calin]]></description>
		<content:encoded><![CDATA[<p>Hello there.</p>
<p>With all due respect, this seems to be a case where proper database sizing was not made since the very beginning. What you can do, and this is just my two cents, is to monitor the growth of your DB over time, and start from there. I&#8217;m pretty sure that you&#8217;ll need to add additional disks if moving historical data to a data warehouse is not an option.</p>
<p>best regards,<br />
calin</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: calin</title>
		<link>http://blog.sqlauthority.com/2009/01/25/sql-server-shrinking-ndf-and-mdf-files-a-safe-operation/#comment-76285</link>
		<dc:creator><![CDATA[calin]]></dc:creator>
		<pubDate>Tue, 15 Jun 2010 06:48:08 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2118#comment-76285</guid>
		<description><![CDATA[Hi there.

Could be a bug, actually, please look here: http://connect.microsoft.com/SQLServer/feedback/details/291408/dbcc-shrinkfile-and-shrinkdatabase-failing-after-backup . As a side note, you can try to increase the file by few MB, and only then attempt to shrink it. Please let us know if it worked.

best regards,
calin]]></description>
		<content:encoded><![CDATA[<p>Hi there.</p>
<p>Could be a bug, actually, please look here: <a href="http://connect.microsoft.com/SQLServer/feedback/details/291408/dbcc-shrinkfile-and-shrinkdatabase-failing-after-backup" rel="nofollow">http://connect.microsoft.com/SQLServer/feedback/details/291408/dbcc-shrinkfile-and-shrinkdatabase-failing-after-backup</a> . As a side note, you can try to increase the file by few MB, and only then attempt to shrink it. Please let us know if it worked.</p>
<p>best regards,<br />
calin</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER – Shrinking NDF and MDF Files – Readers’ Opinion Journey to SQL Authority with Pinal Dave</title>
		<link>http://blog.sqlauthority.com/2009/01/25/sql-server-shrinking-ndf-and-mdf-files-a-safe-operation/#comment-76262</link>
		<dc:creator><![CDATA[SQL SERVER – Shrinking NDF and MDF Files – Readers’ Opinion Journey to SQL Authority with Pinal Dave]]></dc:creator>
		<pubDate>Tue, 15 Jun 2010 01:32:02 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2118#comment-76262</guid>
		<description><![CDATA[[...] 15, 2010 by pinaldave    Previously, I had written a blog post about SQL SERVER – Shrinking NDF and MDF Files – A Safe Operation. After that, I have written the following blog post that talks about the advantage and disadvantage [...]]]></description>
		<content:encoded><![CDATA[<p>[...] 15, 2010 by pinaldave    Previously, I had written a blog post about SQL SERVER – Shrinking NDF and MDF Files – A Safe Operation. After that, I have written the following blog post that talks about the advantage and disadvantage [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Biju.K.S</title>
		<link>http://blog.sqlauthority.com/2009/01/25/sql-server-shrinking-ndf-and-mdf-files-a-safe-operation/#comment-75326</link>
		<dc:creator><![CDATA[Biju.K.S]]></dc:creator>
		<pubDate>Wed, 09 Jun 2010 14:07:25 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2118#comment-75326</guid>
		<description><![CDATA[.ndf is for secondary data file extension, But some database will not have this file.  For more information please search &#039;database architecture&#039;.]]></description>
		<content:encoded><![CDATA[<p>.ndf is for secondary data file extension, But some database will not have this file.  For more information please search &#8216;database architecture&#8217;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sanju</title>
		<link>http://blog.sqlauthority.com/2009/01/25/sql-server-shrinking-ndf-and-mdf-files-a-safe-operation/#comment-75217</link>
		<dc:creator><![CDATA[Sanju]]></dc:creator>
		<pubDate>Tue, 08 Jun 2010 15:55:55 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2118#comment-75217</guid>
		<description><![CDATA[Hello Imran/Pinal,

I want to know the difference between shrinkfile and shrink database. Is it about shrinking mdf and ldf files or more than that ?


Thanks,
Sanju]]></description>
		<content:encoded><![CDATA[<p>Hello Imran/Pinal,</p>
<p>I want to know the difference between shrinkfile and shrink database. Is it about shrinking mdf and ldf files or more than that ?</p>
<p>Thanks,<br />
Sanju</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aashish Vaghela</title>
		<link>http://blog.sqlauthority.com/2009/01/25/sql-server-shrinking-ndf-and-mdf-files-a-safe-operation/#comment-74868</link>
		<dc:creator><![CDATA[Aashish Vaghela]]></dc:creator>
		<pubDate>Sat, 05 Jun 2010 13:07:03 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2118#comment-74868</guid>
		<description><![CDATA[Thanks a Trillion Imran for such an exhaustive explanation.
Now I know for sure what is an NDF file &amp; how it could be used. Also, what DBCC SHRINKDATABASE (DBName, PctVal)
does.

Thanks again &amp; God Bless !!]]></description>
		<content:encoded><![CDATA[<p>Thanks a Trillion Imran for such an exhaustive explanation.<br />
Now I know for sure what is an NDF file &amp; how it could be used. Also, what DBCC SHRINKDATABASE (DBName, PctVal)<br />
does.</p>
<p>Thanks again &amp; God Bless !!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Imran Mohammed</title>
		<link>http://blog.sqlauthority.com/2009/01/25/sql-server-shrinking-ndf-and-mdf-files-a-safe-operation/#comment-74810</link>
		<dc:creator><![CDATA[Imran Mohammed]]></dc:creator>
		<pubDate>Sat, 05 Jun 2010 03:02:25 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2118#comment-74810</guid>
		<description><![CDATA[Hello Aashish,

Before I explain you the concept of Shrink Database. Lets understand about Database Files. 

Typically when we create a new database inside SQL Server, SQl Server creates two physical files on Operating System.

One with .MDF Extension and other with .LDF Extension.
.MDF is called as Primary Data File.
.LDF is called as Transactional Log file.

If you add (one or more) data files to a database, the physical file that will be created on operating system will have extension of .NDF,it is called as Secondary Data File. 

Where as, when you add (one or more) log files to a database, the physical file that will be created on Operating System will have the same extension as .LDF.

Question is, why new data file has different extension (.NDF) and why is it called as secondary data file and why .MDF file is called as primary data file. 

Answer: 
Note: Explanation is based on my limited knowledge of SQL Server, Experts please comment. 

Data file with .MDF extension is called as Primary Data File, the reason behind it is, it contains Database Catalogs.

Catalogs means Meta Data. Meta Data is Data about Data.

An example for meta data includes system objects that stores information about other objects, but not the data stored by users,

sysobjects stores information about all objects in that database.
sysindexes stores information about all indexes and rows of every table in that database.
syscolumns stores information about all columns each table has in that database.
sysusers stores how many users that database has.

So Metadata is storing information about other objects, meta data is not the transactional data that user enters, its a system data about the data.

Because Primary Data File (.MDF) has important information about database, it is treated special and is given the name, Primary Data file, because it contains Database Catalogs. This file is present in Primary File Group.

You can always create additional objects (Tables, indexes etc.) in Primary data file (This file is present in Primary File group), by mentioning that you want to create this object under primary file group.

Any additional data file that you add to the database will have only transactional data but no metadata, and is why called as Secondary data file with the extension .NDF, so that you can easily identify Primary Data File and Secondary Dat File(s).


There are many advantages of storing data in different Files (Under different filegroup). You can put your read only tables in one file (file group) and read write tables in another file (file group) and take backup of only filegroup that has read write data, so that you can avoid taking backup of read only data that never changes. Creating additional files on different physical hard disks also improves I/O performance.

A real-time scenario where we use Files could be,
Say, you have created a database MYDB on D-Drive, it has 50 GB Space. And you have 1 database file (.MDF) and 1 Log File on D-Drive and say all of that 50 GB space has been used and you do not have any free space left, you want to add additional space to the database, one easy option would be to add one more physical hard disk to server, add new data file to MYDB database and create this new data file on new hard disk and move some of the objects from one file to other file, and make the filegroup under which you added new file as default File group, so that any new object that is created gets created in new files, unless specified.


Now that we got basic idea of what data files are and what type of data they store and why they are named the way they are, lets move to next topic, Shrinking.

First of all, I disagree with Microsoft terminology for naming this feature as Shrinking. Shrinking in regular terms means reducing size of a file by compressing it. BUT in SQL Server, shrinking DOES NOT means compressing, shrinking in SQL Server means, removing empty space from database files and releasing the empty space either to operating system or to SQL Server. 

Lets understand this with an example. 
Say you have a database MyDB with size 50 GB and Free Space 20 GB, what this means is, 30GB in the database is filled with data and 20 GB of space is free in the database that is not currently utilized by SQl Server(Database), it is reserved but not in use. If you choose to shrink database and to release empty space to Operating system, MIND YOU, you can only shrink the database size to 30 GB (in our example) , you cannot shrink the database to size less than space filled with data.

So, if you have a database that is full with no empty space in data file and log file (you dont have extra disk space to set Auto growth option ON), YOU CANNOT issue SHRINK Database/File command, because of two reasons,

1. There is no empty space to be released, because shrink command does not compress database, it only removes empty space from the database files and there is no empty space.
2. Remember, Shrink command is a logged operation, When we perform Shrink operation, this information is logged in log file, and if there is no empty space in log file, SQl Server cannot write to log file because there is no empty space in logfile and that is why you cannot shrink a database.

Shrinking best practices:
1. Use DBCC Shrinkfile (&#039;Filename&#039;, Estimated_File_Size_After_Shrink (in MB) ) instead of DBCC Shrinkdatabase command. 
2. Do not shrink file/database in big intervals, shrink in small intervals and issue shrink command multiple times, 

Say, you have a database file in database MYDB, reserve space for this file is 50 GB with 20 GB free space (Which means 30 Gb is occupied space). Dont shrink this file from 50 GB to 30 Gb in one shot. shrink in small intervals like shrink &lt;5GB in 1 shot, repeat this process 4 times. This will be more effective.

3. Do not shrink your database when running backup jobs, backup jobs will fail.
4. Always Rebuild your indexes after you shrink database, because you are removing empty space from the database, this means data pages will be rearranged creating lot of (External and Internal) fragmentation. SQL Server 2008, how ever provides an option that can aviod this case (ofcourse by adding extra overhead on the server). 
Note: Rebuilding Clustered Indexe will put a lock on the tables and table will not be available for use untill SQl Server rebuilds clustered index on the table, So do not rebuild your clustered indexe when users are connected to the database or when database is in use.
5. Do not Stop Shrink Process in middle, If stopped database status might be changed from ONLINE to some other status, in simple words, if you do not have a database backup, you are SCREWED BIG TIME. Don;t ever try to attempt to stop Shrink Command manually, give time to complete its process.

Now answering your question,
(1) What are the USEDPAGES &amp; ESTIMATEDPAGES that appear on the Results Pane after using the DBCC SHRINKDATABASE (NorthWind, 10) ?? 
According to Books Online (For SQl Server 2000), it means
UsedPages: The number of 8-KB pages currently used by the file. 
EstimatedPages: The number of 8-KB pages that SQL Server estimates the file could be shrunk down to. 

Important Note: Before asking any question, make sure you go through books online or search on google once. 
Reason for doing so have many advantages, 
1. if some one else already have had this question before, changes that it is answered are more than 50 %.
2. This reduces your waiting time for the answer.

(2) What is the difference between Shrinking the Database using DBCC command like the one above &amp; Shrinking it from the Enterprise Manager Console, by Right-Clicking the database, going to TASKS &amp; then Select SHRINK Option, on a SQL Server 2000 environment ?
As far as my knowledge goes, there is no difference, both will work the same way, one advantage of using this command from query analyzer is, your console wont be freezed. You can do peform your regular activities using Enterprise Manager.

(3) what is this NDF file that is discussed above. Never heard of it. What is it used for ? Is it used by end-users, DBAs or the SERVER/SYSTEM itself ??
NDF File is secondary data file. You never heard of it because when database is created, SQL Server creates database by default with only 1 data file (.MDF) and 1 log file (.LDF) or how ever you model database has been setup, because model database is template used for every time you create new database using CREATE DATABASE Command. Unless you have added an extra data file, you will not see it. This file is used by SQL Server to store data saved by users.

Hope this information helps. 

Experts please comment, if what I understand is not what Microsoft guys meant.]]></description>
		<content:encoded><![CDATA[<p>Hello Aashish,</p>
<p>Before I explain you the concept of Shrink Database. Lets understand about Database Files. </p>
<p>Typically when we create a new database inside SQL Server, SQl Server creates two physical files on Operating System.</p>
<p>One with .MDF Extension and other with .LDF Extension.<br />
.MDF is called as Primary Data File.<br />
.LDF is called as Transactional Log file.</p>
<p>If you add (one or more) data files to a database, the physical file that will be created on operating system will have extension of .NDF,it is called as Secondary Data File. </p>
<p>Where as, when you add (one or more) log files to a database, the physical file that will be created on Operating System will have the same extension as .LDF.</p>
<p>Question is, why new data file has different extension (.NDF) and why is it called as secondary data file and why .MDF file is called as primary data file. </p>
<p>Answer:<br />
Note: Explanation is based on my limited knowledge of SQL Server, Experts please comment. </p>
<p>Data file with .MDF extension is called as Primary Data File, the reason behind it is, it contains Database Catalogs.</p>
<p>Catalogs means Meta Data. Meta Data is Data about Data.</p>
<p>An example for meta data includes system objects that stores information about other objects, but not the data stored by users,</p>
<p>sysobjects stores information about all objects in that database.<br />
sysindexes stores information about all indexes and rows of every table in that database.<br />
syscolumns stores information about all columns each table has in that database.<br />
sysusers stores how many users that database has.</p>
<p>So Metadata is storing information about other objects, meta data is not the transactional data that user enters, its a system data about the data.</p>
<p>Because Primary Data File (.MDF) has important information about database, it is treated special and is given the name, Primary Data file, because it contains Database Catalogs. This file is present in Primary File Group.</p>
<p>You can always create additional objects (Tables, indexes etc.) in Primary data file (This file is present in Primary File group), by mentioning that you want to create this object under primary file group.</p>
<p>Any additional data file that you add to the database will have only transactional data but no metadata, and is why called as Secondary data file with the extension .NDF, so that you can easily identify Primary Data File and Secondary Dat File(s).</p>
<p>There are many advantages of storing data in different Files (Under different filegroup). You can put your read only tables in one file (file group) and read write tables in another file (file group) and take backup of only filegroup that has read write data, so that you can avoid taking backup of read only data that never changes. Creating additional files on different physical hard disks also improves I/O performance.</p>
<p>A real-time scenario where we use Files could be,<br />
Say, you have created a database MYDB on D-Drive, it has 50 GB Space. And you have 1 database file (.MDF) and 1 Log File on D-Drive and say all of that 50 GB space has been used and you do not have any free space left, you want to add additional space to the database, one easy option would be to add one more physical hard disk to server, add new data file to MYDB database and create this new data file on new hard disk and move some of the objects from one file to other file, and make the filegroup under which you added new file as default File group, so that any new object that is created gets created in new files, unless specified.</p>
<p>Now that we got basic idea of what data files are and what type of data they store and why they are named the way they are, lets move to next topic, Shrinking.</p>
<p>First of all, I disagree with Microsoft terminology for naming this feature as Shrinking. Shrinking in regular terms means reducing size of a file by compressing it. BUT in SQL Server, shrinking DOES NOT means compressing, shrinking in SQL Server means, removing empty space from database files and releasing the empty space either to operating system or to SQL Server. </p>
<p>Lets understand this with an example.<br />
Say you have a database MyDB with size 50 GB and Free Space 20 GB, what this means is, 30GB in the database is filled with data and 20 GB of space is free in the database that is not currently utilized by SQl Server(Database), it is reserved but not in use. If you choose to shrink database and to release empty space to Operating system, MIND YOU, you can only shrink the database size to 30 GB (in our example) , you cannot shrink the database to size less than space filled with data.</p>
<p>So, if you have a database that is full with no empty space in data file and log file (you dont have extra disk space to set Auto growth option ON), YOU CANNOT issue SHRINK Database/File command, because of two reasons,</p>
<p>1. There is no empty space to be released, because shrink command does not compress database, it only removes empty space from the database files and there is no empty space.<br />
2. Remember, Shrink command is a logged operation, When we perform Shrink operation, this information is logged in log file, and if there is no empty space in log file, SQl Server cannot write to log file because there is no empty space in logfile and that is why you cannot shrink a database.</p>
<p>Shrinking best practices:<br />
1. Use DBCC Shrinkfile (&#8216;Filename&#8217;, Estimated_File_Size_After_Shrink (in MB) ) instead of DBCC Shrinkdatabase command.<br />
2. Do not shrink file/database in big intervals, shrink in small intervals and issue shrink command multiple times, </p>
<p>Say, you have a database file in database MYDB, reserve space for this file is 50 GB with 20 GB free space (Which means 30 Gb is occupied space). Dont shrink this file from 50 GB to 30 Gb in one shot. shrink in small intervals like shrink &lt;5GB in 1 shot, repeat this process 4 times. This will be more effective.</p>
<p>3. Do not shrink your database when running backup jobs, backup jobs will fail.<br />
4. Always Rebuild your indexes after you shrink database, because you are removing empty space from the database, this means data pages will be rearranged creating lot of (External and Internal) fragmentation. SQL Server 2008, how ever provides an option that can aviod this case (ofcourse by adding extra overhead on the server).<br />
Note: Rebuilding Clustered Indexe will put a lock on the tables and table will not be available for use untill SQl Server rebuilds clustered index on the table, So do not rebuild your clustered indexe when users are connected to the database or when database is in use.<br />
5. Do not Stop Shrink Process in middle, If stopped database status might be changed from ONLINE to some other status, in simple words, if you do not have a database backup, you are SCREWED BIG TIME. Don;t ever try to attempt to stop Shrink Command manually, give time to complete its process.</p>
<p>Now answering your question,<br />
(1) What are the USEDPAGES &amp; ESTIMATEDPAGES that appear on the Results Pane after using the DBCC SHRINKDATABASE (NorthWind, 10) ??<br />
According to Books Online (For SQl Server 2000), it means<br />
UsedPages: The number of 8-KB pages currently used by the file.<br />
EstimatedPages: The number of 8-KB pages that SQL Server estimates the file could be shrunk down to. </p>
<p>Important Note: Before asking any question, make sure you go through books online or search on google once.<br />
Reason for doing so have many advantages,<br />
1. if some one else already have had this question before, changes that it is answered are more than 50 %.<br />
2. This reduces your waiting time for the answer.</p>
<p>(2) What is the difference between Shrinking the Database using DBCC command like the one above &amp; Shrinking it from the Enterprise Manager Console, by Right-Clicking the database, going to TASKS &amp; then Select SHRINK Option, on a SQL Server 2000 environment ?<br />
As far as my knowledge goes, there is no difference, both will work the same way, one advantage of using this command from query analyzer is, your console wont be freezed. You can do peform your regular activities using Enterprise Manager.</p>
<p>(3) what is this NDF file that is discussed above. Never heard of it. What is it used for ? Is it used by end-users, DBAs or the SERVER/SYSTEM itself ??<br />
NDF File is secondary data file. You never heard of it because when database is created, SQL Server creates database by default with only 1 data file (.MDF) and 1 log file (.LDF) or how ever you model database has been setup, because model database is template used for every time you create new database using CREATE DATABASE Command. Unless you have added an extra data file, you will not see it. This file is used by SQL Server to store data saved by users.</p>
<p>Hope this information helps. </p>
<p>Experts please comment, if what I understand is not what Microsoft guys meant.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan</title>
		<link>http://blog.sqlauthority.com/2009/01/25/sql-server-shrinking-ndf-and-mdf-files-a-safe-operation/#comment-74755</link>
		<dc:creator><![CDATA[Dan]]></dc:creator>
		<pubDate>Fri, 04 Jun 2010 13:12:10 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2118#comment-74755</guid>
		<description><![CDATA[Hi Pinal.

We have several large databases. Due to their size we have been forced to spread them across several drives.
The largest one have been spread to 5 different drives in the following pattern:

drive:actual sisze(KB)
J:314 468 352 
D:312 252 288
N:143 158 208
O:204 800 000
P:153 600 000 

The J drive is now full, with only 10.0 MB free.
Shrink takes forever, and it seems to fail often.

I can put in extra drives, but is this really the only option?

Best regards
Dan]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal.</p>
<p>We have several large databases. Due to their size we have been forced to spread them across several drives.<br />
The largest one have been spread to 5 different drives in the following pattern:</p>
<p>drive:actual sisze(KB)<br />
J:314 468 352<br />
D:312 252 288<br />
N:143 158 208<br />
O:204 800 000<br />
P:153 600 000 </p>
<p>The J drive is now full, with only 10.0 MB free.<br />
Shrink takes forever, and it seems to fail often.</p>
<p>I can put in extra drives, but is this really the only option?</p>
<p>Best regards<br />
Dan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aashish Vaghela</title>
		<link>http://blog.sqlauthority.com/2009/01/25/sql-server-shrinking-ndf-and-mdf-files-a-safe-operation/#comment-74669</link>
		<dc:creator><![CDATA[Aashish Vaghela]]></dc:creator>
		<pubDate>Fri, 04 Jun 2010 00:49:03 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2118#comment-74669</guid>
		<description><![CDATA[Oh,

 Forgot to ask one more thing.

 MDF is the actual Database File, whereas LDF
 is the LOG file. 

 But what is this NDF file that is discussed above. 
 Never heard of it. What is it used for ? Is it used 
 by end-users, DBAs or the SERVER/SYSTEM itself ??

Thanks again,

Aashish.]]></description>
		<content:encoded><![CDATA[<p>Oh,</p>
<p> Forgot to ask one more thing.</p>
<p> MDF is the actual Database File, whereas LDF<br />
 is the LOG file. </p>
<p> But what is this NDF file that is discussed above.<br />
 Never heard of it. What is it used for ? Is it used<br />
 by end-users, DBAs or the SERVER/SYSTEM itself ??</p>
<p>Thanks again,</p>
<p>Aashish.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aashish Vaghela</title>
		<link>http://blog.sqlauthority.com/2009/01/25/sql-server-shrinking-ndf-and-mdf-files-a-safe-operation/#comment-74667</link>
		<dc:creator><![CDATA[Aashish Vaghela]]></dc:creator>
		<pubDate>Fri, 04 Jun 2010 00:46:33 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2118#comment-74667</guid>
		<description><![CDATA[Hello Pinal,

Just a couple of quick questions here.

(1) What are the USEDPAGES &amp; ESTIMATEDPAGES that 
appear on the Results Pane after using the
DBCC SHRINKDATABASE (NorthWind, 10)   ?? 

(2) What is the difference between Shrinking the 
Database using DBCC command like the one above &amp;
 Shrinking it from the Enterprise Manager Console,
 by Right-Clicking the database, going to TASKS &amp; then
 Select SHRINK Option, on a SQL Server 2000 environment ?

Thanks in Advance,

Aashish.]]></description>
		<content:encoded><![CDATA[<p>Hello Pinal,</p>
<p>Just a couple of quick questions here.</p>
<p>(1) What are the USEDPAGES &amp; ESTIMATEDPAGES that<br />
appear on the Results Pane after using the<br />
DBCC SHRINKDATABASE (NorthWind, 10)   ?? </p>
<p>(2) What is the difference between Shrinking the<br />
Database using DBCC command like the one above &amp;<br />
 Shrinking it from the Enterprise Manager Console,<br />
 by Right-Clicking the database, going to TASKS &amp; then<br />
 Select SHRINK Option, on a SQL Server 2000 environment ?</p>
<p>Thanks in Advance,</p>
<p>Aashish.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bill Gibbons</title>
		<link>http://blog.sqlauthority.com/2009/01/25/sql-server-shrinking-ndf-and-mdf-files-a-safe-operation/#comment-72912</link>
		<dc:creator><![CDATA[Bill Gibbons]]></dc:creator>
		<pubDate>Mon, 24 May 2010 18:18:27 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=2118#comment-72912</guid>
		<description><![CDATA[Pinal,

I am trying to SHRINK an .ndf . It is one of many. All of the others will shrink.  One keeps telling me &quot;File ID 15 of database ID 8 cannot be shrunk as it is either being shrunk by another process or is empty&quot;.

I check running procedures and there are none.  Can you tell me how to discover the culprit ?  There is very little disk space on that volume. Could this be the real cause ?

I&#039;m still using SQL 2005.

Microsoft SQL Server Management Studio 9.00.1399.00
Microsoft Analysis Services Client Tools	2005.090.1399.00
Microsoft Data Access Components (MDAC) 2000.085.1117.00 (xpsp_sp2_rtm.040803-2158)
Microsoft MSXML	2.6 3.0 4.0 5.0 6.0 
Microsoft Internet Explorer 	6.0.2900.2180
Microsoft .NET Framework 	2.0.50727.3053
Operating System		5.1.2600

Any ideas ?]]></description>
		<content:encoded><![CDATA[<p>Pinal,</p>
<p>I am trying to SHRINK an .ndf . It is one of many. All of the others will shrink.  One keeps telling me &#8220;File ID 15 of database ID 8 cannot be shrunk as it is either being shrunk by another process or is empty&#8221;.</p>
<p>I check running procedures and there are none.  Can you tell me how to discover the culprit ?  There is very little disk space on that volume. Could this be the real cause ?</p>
<p>I&#8217;m still using SQL 2005.</p>
<p>Microsoft SQL Server Management Studio 9.00.1399.00<br />
Microsoft Analysis Services Client Tools	2005.090.1399.00<br />
Microsoft Data Access Components (MDAC) 2000.085.1117.00 (xpsp_sp2_rtm.040803-2158)<br />
Microsoft MSXML	2.6 3.0 4.0 5.0 6.0<br />
Microsoft Internet Explorer 	6.0.2900.2180<br />
Microsoft .NET Framework 	2.0.50727.3053<br />
Operating System		5.1.2600</p>
<p>Any ideas ?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

