Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reclaim space in SQL Server 2005 database when dropping tables permanently

I'm dropping out massive numbers of tables out of a SQL Server 2005 database. How do I shrink the database - assuming I'm not replacing the data or the tables? I'm archiving stuff to another db.

like image 568
Caveatrob Avatar asked Dec 20 '25 22:12

Caveatrob


1 Answers

DBCC Shrinkdatabase(0) --  Currently selected database

or

DBCC Shrinkdatabase(<databasename>) --  Named database

However, shrinking files will likely fragment your tables, particularly larger onces, as contents of tables get moved about within the file, so once shrunk it's a good idea to defragment your tables. This, of course, will make your files grow again, but probably not so large as they were before you dropped your old tables. (Err, that assumes that the dropped tables contained large quantities of data...)

like image 127
Philip Kelley Avatar answered Dec 22 '25 20:12

Philip Kelley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!