Shrink Method
未來的 Microsoft SQL Server 版本將移除這項功能。請避免在新的開發工作中使用這項功能,並規劃修改目前使用這項功能的應用程式。
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.
語法
object.Shrink(NewSize, Truncate)
Parts
object
Expression that evaluates to an object in the Applies To list.NewSize
Long integer that specifies a new target size as described in Settings.Truncate
Long integer that directs method behavior as described in Settings.
Prototype (C/C++)
HRESULT Shrink(long NewSize, SQLDMO_SHRINK_TYPE Truncate);
備註
For the Database object, the NewSize argument is set 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 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 using these values.
SQLDMOShrink_Default
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
Migrate all data from the referenced file to other files in the same filegroup. (DBFile and LogFile object only)SQLDMOShrink_NoTruncate
Data in pages located at the end of the file(s) is moved to pages earlier in the file(s).SQLDMOShrink_TruncateOnly
Data distribution is not affected. File(s) are truncated to reflect allocated space, recovering free space at the end of any file.