SQL Clone
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)

Grow\Shrink all datafiles SQL 2005\2008

By Allan Roodt,

This script is essentially a generator which outputs a script in the query window which will grow all the datafiles ( or shrink them ) to the same amount as specified. This saves time having to write out long queries for multiple databases with multiple datafiles. The main purpose behind this script is if the user works on a system where the datafiles has to be the same size to ensure consistency, this script will help them out.

If the user enters an amount ( maybe by accident or on purpose ) which is less than what the current size of the primary MDF datafile ( which to my knowlege is usually the biggest ), an added security feature is in place warning the user that a shrink will occur, though if this is what you want, you have to provide a special parameter ( @vcYES which is outputted in the query ) to acknowlege that you are sure you want to continue ( think of it as SQL's way of clicking YES or no like in Windows ).

1)To use this script, paste it in a query window and connect to the database you want to work on.
2)Enter the current database name you are on in the @vcDatabaseName variable
3)Indicate to how many MB you want to grow\shrink the datafile in the @vcGrowAmountMB variable
4)Run the script and copy the result outputted into a new query window. This will be the script which does the work for you.
5)Do something else because now you have alot of free time :)

Total article views: 2264 | Views in the last 30 days: 2
Related Articles

Delete Datafiles



Quick and dirty script to ascertain datafile headroom

This is quick script to ascertain datafile headroom based on current size of the data in a file agai...


SQL Datafile... How to protect ????

SQL Datafile... How to protect ????


Windows Group Membership Checker

A script to reveal which logins have access to your sql server via windows groups.