DBCC ShrinkDatabase() DBCC ShrinkFile()
- Do I need to run both DBCC commands in order to shrink the database?
- What is the difference between these two above?
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It only takes a minute to sign up.Sign up to join this community
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
You almost never use
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.
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.
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'