Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 Shrink file

Author  Topic 

Norman Castle
Starting Member

9 Posts

Posted - 2011-04-29 : 21:18:16
I'm having problems with Shrinkfile. I wish to use the option to migrate the data to other files, and then delete the file.

It takes several hours to operate a single shrink operation. And then it usually gives an error message. It only works sometimes.

Any ideas what could be wrong?

I am, by the way, using SQL Server management Studio. How do I get the file ID number to run it as a SQL statement?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-04-30 : 00:10:49
You need to perform the shrink in small increments, such as 200MB.

You don't need the file id number. You can specify the logical name.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Norman Castle
Starting Member

9 Posts

Posted - 2011-04-30 : 00:32:15
How do I shrink in small increments?

I can't see how to do it except for unused space. I mean, if the file is 950Mb, and only 650 is used, then I can reduce the size by 200 easily. But I can't get it any smaller than 650.

If I check the option to move the data to other files, it tries to move all of it. I don't see how to move only some of it.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-04-30 : 00:46:04
Here you go: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=80355

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Norman Castle
Starting Member

9 Posts

Posted - 2011-04-30 : 09:24:42
quote:
Originally posted by tkizer

Here you go: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=80355


I've tried running the linked code. It seems to only reduce the unused space.
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-04-30 : 11:03:02
You have to use the EMPTYFILE option of the DBCC SHRINKFILE command. You also need at least one other file in the same filegroup large enough to accept all the data from the file you're trying to delete.
Go to Top of Page

Norman Castle
Starting Member

9 Posts

Posted - 2011-04-30 : 12:40:44
quote:
You have to use the EMPTYFILE option of the DBCC SHRINKFILE command.


Can this be done by increments? What's the syntax for it?

quote:
You also need at least one other file in the same filegroup large enough to accept all the data from the file you're trying to delete.


Enough space in a single file? Or is it okay if I have several files, with enough space when combined?

And if I don't have enough space, but the files are set to autogrow, will that do?
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-04-30 : 21:43:59
EMPTYFILE is an all-or-nothing prospect, it moves everything out of the file you're shrinking.

You don't need to have enough space in a single file, just enough in the other files of the filegroup. You can also create a new filegroup and re-create the clustered index on the new filegroup, that will move the data. You'd have to repeat that for any nonculstered indexes in that file.
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2011-05-02 : 20:46:52
by the way, you realize you are going to cause fragmentation by shrinking your data files right?

Read Why you should not shrink your files @ http://www.sqlskills.com/BLOGS/PAUL/category/Shrink.aspx#p7

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page
   

- Advertisement -