Search This Blog

Tuesday, August 7, 2012

DBCC SHRINKDATABASE (Transact-SQL)


Shrinks the size of the data and log files in the specified database.


DBCC SHRINKDATABASE
( database_name | database_id | 0
[ , target_percent ]
[ , { NOTRUNCATE | TRUNCATEONLY } ]
)
[ WITH NO_INFOMSGS ]




Arguments

database_name | database_id | 0

Is the name or ID of the database to be shrunk. If 0 is specified, the current database is used.

target_percent

Is the percentage of free space that you want left in the database file after the database has been shrunk.

NOTRUNCATE

Compacts the data in data files by moving allocated pages from the end of a file to unallocated pages in the front of the file. target_percent is optional.

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, when NOTRUNCATE is specified, the database appears not to shrink.

NOTRUNCATE is applicable only to data files. The log files are not affected.

TRUNCATEONLY

Releases all free space at the end of the file to the operating system but does not perform any page movement inside the file. The data file is shrunk only to the last allocated extent. target_percent is ignored if specified with TRUNCATEONLY.

TRUNCATEONLY is applicable only to data files. The log files are not affected.

WITH NO_INFOMSGS
Suppresses all informational messages that have severity levels from 0 through 10.