Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Shrink Database Files in Size Increments

By Boris Moyse,

Shrinking database files can be a very resource intensive task when dealing with large files.
Performing a DBCC Shrinkfile in small increments should help. This script will automate this task.
Set your desired target file size and set the increment size for each shrink operation.
Change the increment size accordingly based on your database environment. Start with a small
increment size of 128MB and see how it goes.

Performing a Shrink operation should only be done when absolutely necessary as this can cause disk fragmentation at the file system level.

Note...remember to remove the < > characters form the first 3 SET statements in the script.

P.S.....I'm a somewhat of a newbie at programming and therefor like to keep my scripts simple. Any and all suggestions to improve this script are welcome.

Total article views: 2415 | Views in the last 30 days: 5
 
Related Articles
FORUM

script to shrink db

script to shrink db

FORUM

shrinking

shrinking

BLOG

SQL database Incremental Shrink TSQL

When we shrink a SQL database through GUI we usually find the database never releases all the free...

SCRIPT

Fastes way to increment an id column

This script shows the fastest way to increment an INT id column.

BLOG

Shrinking the log file script for SQL server database

Shrinking the log file script for SQL server database                                This script m...

Tags
maintenance    
 
Contribute