Shrink all databases on server (sql)

Database serverIt all started with a client call (like usual)…

About a month ago, I got a call from a client of mine saying he has 2 database servers, each holding about 150 databases.

The servers were both SQL Server 2008, he had 2 HD’s with 74GB each and there was absolutely no space on any of them.

After a short research I found that the backup files were absolutely huge and fill the disk up to a point that the server had no space to store any more data and the website connected to that database crashed.

Without going too much into details why these things happen (bad programming) I will give you a method to fix this.

It is recommended to backup your databases to an external HD before doing this, this way you will have the full backup at all times.

Simply run this script, your databases (all of them) will shrink the log file, creating more room on the HD for you to use.

Good luck

Submit to Hacker News

[NOTE] This post has been imported to Hugo from a Wordpress blog. It may be broken, missing images, code snippets or other information.

[NOTE] updated January 16, 2010. It's 3299 days old . This article may have outdated content.