Sql-server – Release unused space in SQL Server database

shrinksql server

I have a SQL Server database with roughly 1.5 TB test data (size of core tables are calculated using sp_spaceused 'tablename'). At the time of data creation process, I have allocated 350 GB to each data file, and my database contains 9 data files and 3 log files.

I want to shrink the database and release unused space before taking a back up. In the database shrink options it shows Available free space as 51%.

Using Management Studio tasks-> shrink options:

  • I shrunk individual data files and log files.
  • then, shrunk the database.

But still shows as 51% free space is available. Can anyone tell me what I'm doing wrong there or am I missing any steps on shrinking process?

What I'm looking for is, since there is a lot of unused space in the database, I want to release it, so the database size gets reduced.

Best Answer

You can script the SQL commands that SSMS generates. Without us knowing what commands you execute, we don't have much to go on.

Also, pls be specific about each file and the file size. You have 12 files. How large was each file before the individual file shrink, and what was the file size after the individual file shrink?

Did you use the TRUNCATEONLY options of the DBCC SHRINKFILE commands? That is the default in the GUI.

Finally, no need to do a "final" DBCC SHRINKDATABASE. Work with each file separately instead.