What’s the difference between “shrink” file vs simply reducing the initial size?

Posted on

Question :

I’m totally new in DB Administration. So i got confused about the “file shrink” functionality offered on SQL Server Management Studio (SMSS) or via T-SQL. Why I would I need to use that “file shrink” functionality if I can simply lower the initial size of the db?

enter image description here

I tried to (edit) reduce the initial size of my DB and it succefully reduced my physical file of the db. Which would also work quite the same if I use that “shrink” feature.

Answer :

That “Initial Size” label is misleading. It’s really the “current size” of the file. Also, changing that number and clicking “OK” does a SHRINKFILE behind the scenes, so the two things you’re comparing are actually…the same thing

Here’s my copy of the StackOverflow2010 database (where the current size really is 9,105 MB):

screenshot of the file size of 9105 MB in the SO 2010 data file in SSMS

If I change that to “5”:

screenshot of the file size updated to 5 MB in the SO 2010 data file in SSMS

And then click the “Script” button in the top left of the window, this is what SSMS generates:

USE [StackOverflow2010]
GO
DBCC SHRINKFILE (N'StackOverflow2010' , 5)
GO

So the answer to your question is that these two features of SSMS do the same thing.

By the way, I highly recommend using that “Script” button in SSMS frequently as you are learning. It’s a great way to understand what the SSMS GUI is doing, and is also helpful in automating and overcoming the limitations of the user interface as you get more comfortable with T-SQL scripts.

Note that you should be wary of shrinking database files, see here for more information:

I Need to Shrink My Database – I just freed a lot of space

When is it OK to shrink a Database?

Just a note that MS finally removed that word “Initial” in the GUI in version 18 of SSMS (after my loud complaints 🙂 ). So with a more up-to-date SSMS you would potentially have been less confused.

Leave a Reply

Your email address will not be published.