Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
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: 2253 | Views in the last 30 days: 18
 
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

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones