Shrinks the current database’s specified data or log file size. You can use it to move data from one file to other files in the same filegroup, which empties the file and allows for its database removal. You can shrink a file to less than its size at creation, resetting the minimum file size to the new value.

Use [MyDB]
GO

-- Set to 100 MB Size
DBCC SHRINKFILE (N'MyDB_log', 100)
GO

-- Set to Default Size
DBCC SHRINKFILE (N'MyDB_log', EMPTYFILE)
GO

-- Set to 1GB
DBCC SHRINKFILE (N'MyDB_log' , 1024, TRUNCATEONLY)
GO

TRUNCATEONLY

Releases all free space at the file’s end 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_size is ignored if specified with TRUNCATEONLY.

The TRUNCATEONLY option does not move information in the log, but does remove inactive VLFs from the end of the log file. This option isn’t supported for FILESTREAM filegroup containers.

Sources:

https://docs.microsoft.com/en-us/sql/t-sql/database-console-commands/dbcc-shrinkfile-transact-sql?view=sql-server-ver15

Last modified: July 30, 2020

Author

Comments

Write a Reply or Comment