Sql-server – Shrink SQL Server DB By xgb

shrinksql server

I'm trying to free up some space in a database, firstly by swapping out and archiving partitions. The DB is massive though, and i want to start freeing up some space on the drive, but I don't want to completely shrink the DB as it will take weeks.

Is it possible to shrink a SQL Server DB by say 10gb?

Thanks all!

CM

Best Answer

Yes, you can, but it is not a good idea unless you are 100% certain the database won't grow again. If it will, then shrinking the file to free up space is like vacuuming while confetti is still falling on your carpet, and you should really read one of the many posts out there on how futile it is to shrink files that are just going to grow again. Nothing is gained except your free space % looks a little better for a little while. Big whoop! Do you get a bonus for how much free space is on your disk, even if you can't sustain it?

http://www.sqlskills.com/blogs/paul/why-you-should-not-shrink-your-data-files/

Why Does the Transaction Log Keep Growing or Run Out of Space?

Now, if you really, really, really want to shrink your files, even after reading all of the above material and refusing to heed our warnings, keep reading.

If you want to shrink the data file by 10GB, look at the size it is now, and then use DBCC SHRINKFILE (not DBCC SHRINKDATABASE) and set a size 10GB smaller than that. Look at the size column from sp_helpfile - let's say the file is now 41 GB, and you want it to shrink to 31 GB, then you would say:

DBCC SHRINKFILE(filename, 31000); -- 31,000 MB

You can probably do better math than that (I know 10,000 MB is not exactly 10 GB but you get the idea).