Drop those columns which are no more in use.

For example, After Upgrade from MOSS 2007 to SharePoint Server 2010, we have noticed that all of the upgraded databases in SharePoint Server 2010 were almost 40% – 60% larger in size than before the upgrade.

We’ve decided to DROP those eligible columns and reclaim unused space out of it

Note: We ran this query against 130 GB size table and it took 10 hours to complete its operation online.

Space allocation details of a table can be found using below query:-

sp_spaceused ‘AllDocVersions’

Run the below query and monitor the resource consumption. I would recommend to run it during non-business hours

SELECT GETDATE() /* start time*/

GO /* Actual clean up operation – Online*/



SELECT GETDATE() /* End Time*/

Parameter details:-

DatabaseName= Content_ABCD

TableName= AllDocVersions

Batch_size =100 /Note:- Smaller the size, better the resource governance*/

Is the number of rows processed per transaction. If not specified, or if 0 is specified, the statement processes the whole table in one transaction. Its always better to keep it to small number so that transaction log will not grow abruptly and locks can be handled effectively. You can do it online.

Gather space allocation details one more time and compare it with the previous values

sp_spaceused ‘AllDocVersions’

Its not a recommended practice to shrink the database. In case, the allocation has more than 50% of free space then check for file shrinking option.

Check for available space of the database by issuing the below query.

SELECT name ,file_id,(size/128.0)/1024 ActualSizeofFileinGB,((size/128.0) – CAST(FILEPROPERTY(name, ‘SpaceUsed’) AS int)/128.0)/1024 AS AvailableSpaceInGB FROM sys.database_files;

If AvailableSpaceInGB more than 50% of allocated space, then execute


File id=4

TargetSize = 140000

This can be stopped at any time(Online Operation).

Note: Perform Index Rebuilding Operation once above mentioned steps are over by checking it’s fragmentation level.

About Prashanth Jayaram

DB Technologist, Author, Blogger, Service Delivery Manager at CTS, Automation Expert, Technet WIKI Ninja, MVB and Powershell Geek My Profile: https://social.technet.microsoft.com/profile/prashanth jayaram/ http://www.sqlshack.com/author/prashanth/ http://codingsight.com/author/prashanthjayaram/ https://www.red-gate.com/simple-talk/author/prashanthjayaram/ http://www.sqlservercentral.com/blogs/powersql-by-prashanth-jayaram/ Connect Me: Twitter @prashantjayaram GMAIL powershellsql@gmail.com The articles are published in: http://www.ssas-info.com/analysis-services-articles/ http://db-pub.com/ http://www.sswug.org/sswugresearch/community/
This entry was posted in SQL. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s