Friday, September 26, 2008

Shrink DB Size

Many times we delete/truncate the data from database but database does not release the space to system after that. In that case DBCC ShrinkDatabase and DBCC ShrinkFile can be usefull.

This is something important information about DBCC ShrinkDatabase.

"The NOTRUNCATE option, with or without specifying target_percent, performs the actual data movement operations of DBCC SHRINKDATABASE including the movement of allocated pages from the end of a file to unallocated pages in the front of the file. However, the free space at the end of the file is not returned to the operating system and the physical size of the file does not change. Therefore, data files appear not to shrink when the NOTRUNCATE option is specified.The TRUNCATEONLY option reclaims all free space at the end of the file to the operating system. However, TRUNCATEONLY does not perform any page movement inside the file or files. The specified file is shrunk only to the last allocated extent. target_percent is ignored if specified with the TRUNCATEONLY option."

Personally i would prefer DBCC ShrinkFile and Shrink each file (mdf/ldf) separatly.

If you have very big database then do it off peak times.