The Shrink method attempts to reduce the size of a referenced operating system file, or attempts to reduce the size of all operating system files maintaining the referenced Microsoft® SQL Server™ database.
Database Object | LogFile Object |
DBFile Object |
object.Shrink( NewSize , Truncate )
Part | Description |
---|---|
object | Expression that evaluates to an object in the Applies To list |
NewSize | Long integer specifying a new target size as described in Settings |
Truncate | Long integer directing method behavior as described in Settings |
For the Database object, the NewSize argument is set by using any negative number or a number from 1 through 100. When negative, the Shrink method to attempts to shrink files maintaining the database to their smallest possible sizes. A positive value represents a percentage of the target reserved as unused space. For example, specify 5 to shrink a database leaving five percent free space for future growth.
For the DBFile and LogFile objects, the NewSize argument is set by using any negative number, zero, or any positive integer. When negative, the Shrink method attempts to shrink the referenced file to its smallest possible size. Zero or a positive value represents a target file size as a number of megabytes.
Set the Truncate argument by using these values.
Constant | Value | Description |
---|---|---|
SQLDMOShrink_Default | 0 | Data in pages located at the end of the file(s) is moved to pages earlier in the file(s). File(s) are truncated to reflect allocated space. |
SQLDMOShrink_EmptyFile | 3 | Migrate all data from the referenced file to other files in the same filegroup. (DBFile and LogFile object only). |
SQLDMOShrink_NoTruncate | 1 | Data in pages located at the end of the file(s) is moved to pages earlier in the file(s). |
SQLDMOShrink_TruncateOnly | 2 | Data distribution is not affected. File(s) are truncated to reflect allocated space, recovering free space at the end of any file. |
HRESULT Shrink(
long NewSize, SQLDMO_SHRINK_TYPE Truncate);