DBCC ShrinkDatabase()
DBCC ShrinkFile()
  1. Do I need to run both DBCC commands in order to shrink the database?
  2. What is the difference between these two above?

3 Answers 3



  • DBCC ShrinkDatabase(): shrink all files
  • DBCC ShrinkFile(): just one file

For example, you may have a log backup issue and it's grown out of control so you run DBCC ShrinkFile().

You almost never use ShrinkDatabase.

Before you consider using either command, please read Paul Randal's blog on shrinking.

I'd shrink neither one of the files (mdf, ldf) unless there was a clear reason. The files are the size they are because they need to be. Any blogs suggesting to do so as part of regular maintenance probably don't understand how SQL Server works.

  • 2
    Thanks man. you are right. I just read Brent Ozar blog.. he is literally swearing in his blog "Stop Shrinking Your Database Files. Seriously. Now.".
    – Jango
    Aug 23, 2010 at 19:03
  • And when it is doing the same, why are there different arguments? Nov 6, 2013 at 9:25
  • The link to Paul Randal's blog is broken.
    – Bacon Bits
    Jan 28, 2020 at 22:46
  • filed an edit request to change the link to an archived version of the page as i had a similar discussion recently and found the reference very informative Feb 5, 2020 at 8:09
  • 1
    Very interesting for sure. I have a valid scenario though, we routinely refresh test data from production. We are constrained by space in the test environment, so I had to empty lots of tables that we don't need which free up about 70% of the original size. I have to use shrinkfile in order to reduce the size of the database. Now I wonder about the impact on performance. Hmmm...
    – costa
    Feb 20, 2020 at 20:52

A default database has two files

MyDb.MDF and MyDb.LDF

The MDF file is the data file where the primary partition resides. Depending on your needs, you can partition a database into multiple files. This is done so that data (single or multiple tables) can span multiple files that usually are put on separate hard drives to achieve a higher performance.

If you shrink a database, all files associated with that database will be shrunk.

If you shrink a file, then only the chosen file will be shrunk.

You only need to use the Shrink Database command. But it is not usually a good practice to do this and is not a recommended practice either.

If you tell us what the issue is that you are experiencing, we can give you more information on how to resolve it.

  • Oh..issue is our production server is running out of the disk space. Adding more disk is ideal but i was wondering what else we can do?
    – Jango
    Aug 23, 2010 at 18:42

Most likely we use only dbcc shrinkfile . sp_helpdb 'databasename' provides the list of data&log files in a database.

right click on the mnagement studio, tasks->shrink->file provides how much % you can shrink.

what ever we shrink , it is avilable back on the disk as free space.

eg: use 'databasename' dbcc shrinkfile(fileid,100)

here 100 is 100 MB

fileid can get from sp_helpdb 'databasename'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy