Wednesday, March 21, 2012

How to reduce database file size.

We have a database which was created with an initial file size of 10 gig. Currently it is only using 2 gigs.

We have developers that want to have a copy of the database on their desktops, but do not have 10 gigs free space.

What is the best way to get them a copy of the database while reducing the footprint?I'm assuming you don't want to do DBCC SHRINKDATABASE and DBCC SHRINFILE?|||I would go for generating a script of all the objects, creating a realistic sized DB on the laptop, then using DTS or some such to bring the data over.

It is a bit of a pain when you are dealing with a lot of tables. Especially since Enterprise Manager tends to do things alphabetically, instead of the way you have your foreign keys set up.|||Yeah, we could create a new database on the developers desktop and then DTS everything over. But the general question, I guess, is whether it is possible to shrink a database file below its initial size.

I believe SHRINKDATABASE and SHRINKFILE will only reduce down to the initial size of the file when it was created.|||That's true of SHRINKDATABASE; however, SHRINKFILE will let you shrink lower than the original size. You just need to specify the exact size. For example:

DBCC SHRINKFILE('Northwind_Data',300)|||One caution, though is that dbcc shrinkfile will take a bunch of time if it needs to move a lot of data around. This will also cause the transaction log to grow (which is kind of ironic, eh?). Start off with dbcc shrinkfile (1, truncateonly). This will chop off any of the file that is above the "high water mark" of the data, and is relatively quick.

EDIT: If memory serves, the only limit to the shrinkage is the size of the model database.|||How many objects are we talking about btw?sql

No comments:

Post a Comment