What's the difference between “shrink” file vs simply reducing the initial size?
-
08-03-2021 - |
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?
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.
Solution
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):
If I change that to "5":
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:
OTHER TIPS
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.