Using DBCC SHRINKDATABASE

SQL Server

Why use DBCC SHRINKDATABASE

I don’t recommend you shrink your databases, either through setting AUTO_SHRINK for the database to True, or by regularly running the DBCC SHRINKDATABASE command. However, there may be an event that happens that frees up a significant about of space, like deleting a large table, and you want to reclaim that wasted space.

Using T-SQL command:

DBCC SHRINKDATABASE 
(database_name|database_id|0 
     [,target_percent] 
     [,{NOTRUNCATE|TRUNCATEONLY}])
[WITH NO_INFOMSGS]

As an example, if your database name is SampleDB, you would run this command:

DBCC SHRINKDATABASE (SampleDB, 10);  
GO
Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s