How To Shrink a File to Below the Size value in SQL Server 2005

Posted on 2008-02-05
Medium Priority
Last Modified: 2008-02-14
The database I am working on was created as a restore from a production backup.
The 'Initial Size' of the data file is automatically set to the actual size of the file (or close to it)
In my case, it is 100gb.
I have since added another File Group (and hence file) and moved over half of the tables to it.
I need to reclaim the free space in the original file.

The DBCC SHRINKFILE (N'myDatabase.Primary' , 70000) does not have any effect (presumably because it will not shrink to below the Initial Size)

When I try to reduce the original size using
ALTER DATABASE myDatabase MODIFY FILE (NAME = N'myDatabase.Primary', SIZE = 50gb)
I get the error 'MODIFY FILE failed. Specified size is less than current size.'

Has anyone got any ideas on how I can reclaim this free space when the Initial Size of the file is way too big

thanks in advance


Question by:vikings24
  • 2
  • 2

Expert Comment

ID: 20827545
I'm afraid the only way is to migrate data and objects to another database.

Author Comment

ID: 20828929
thanks maradam

Was hoping it wouldn't come to that, but I thought it may.

On a small database, I created a 2nd file in the Primary Group, then did a shrink file1 EMPTYFILE.
It wouldn't 'move all contents of file1 to other places', but I think it did move most of it.
I then did a shrink of file1 to a small size, and it did work.

I then did a shrink file2 EMPTYFILE, which moved it all back again to file1.

Next step is to try it on the original database (after I can get hold of an extra 100gb temporarily)

What do you think? - would this be preferable (assuming it works)  to migrating to a completely new database?


Assisted Solution

maradam earned 2000 total points
ID: 20830091
I did the same experiment on totally empty database. And I can't shink it below it's initial size. Emptyfile will never work in such a way to make you able to drop the file. It is primary data file and system objects on it will never be moved. So if you can't drop the file you will never be able to shink it below it's initial size. I still think migrating is your only choice.

Accepted Solution

vikings24 earned 0 total points
ID: 20835401
thanks maradam

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question