Sql-server – Is it possible to shrink an .MDF file on a drive with low free space

shrinksql serversql-server-2008

Is there a way to shrink mdf file of database in SQL Server 2008 without using additional space?

Total space in hard disk is 136 GB, the .MDF file size is 124 GB, and the log file size is 2 GB. I have only 12 GB free space and while running the shrink command on the .MDF file, logs are growing and consume the free space — low disk spaces throws the shrinking into a no respond state.

Is there another method to shrink this file without using additional disk space?

Best Answer

To summarize the answers here and to inject my own advice:

1: Blindly shrinking a data file is not the best route. Your data is your data and it is characterized by this size. Unless you are planning on deleting large chunks of data, shrinking is not going to do much of anything. As @billinkc pointed out, simply shrinking the file will not give you any sort of appreciable gain.

2: Running this is going to make your log file grow. Apparently you have your data and log on the same drive. I'd recommend against this for many reasons including space and IO contention.

3: You can certainly create a new data file and put that on a different volume. You could "archive" old data to free space in the current .mdf, or you could leave the current data file as-is and it would become an archive, of sorts.

4: I'm guessing that there are other things on this volume as well. I would move those things as quickly as I could in order to free up space.

If this is enterprise data, I'd push for more disk. This would allow you to separate your data and log files. Additionally, outside of just deleting data, you're going to need more disk to implement Brandon's suggestion anyway.