SQL Server: Generate Shrink Script for each Database File

In this post, I am providing one T-SQL script which generates DBCC Shrinkfile for each database file of the SQL Server.

You can also visit one of the related article:
SQL Server: The TempDB is Full, Shrink it or Move it

Generally, database administrator prefers to execute SHRINK when the database file is occupying more space and require to free unused space.

But In common practice, we should not execute SHRINK on any of SQL Server Database because it generates more fragmentation.
After SHRINK, we should execute the index rebuild or index reorganize to remove all fragmentation.

But still, I am sharing one T-SQL script which generates SHRINK script for each database file.

In one of our standby server, I require to execute SHRINK for each database so I have prepared this script.


Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

If you like this post, then please share it with others.
Please follow dbrnd.com, I will share my experience towards the success of Database Research and Development Activity.

I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.

More from dbrnd.com

Leave a Reply

Be the First to Comment!

Notify of
avatar

wpDiscuz