0

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.

2 Answers 2

6

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?

0
2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.