Re: Problem with database filegroup restructuring in SQL Server?



(jkv10_2005@xxxxxxxxx) writes:
I have the following SQL procedure I am running to clean up a filegroup
and move all data to a single .MDF file:

use <db_name>
print 'Move <db_name> db contents to MDF file'
DBCC SHRINKFILE ('<db_name>_1_Data', EMPTYFILE)
DBCC SHRINKFILE ('<db_name>_Log', EMPTYFILE)
DBCC SHRINKFILE ('<db_name>_2_Data', EMPTYFILE)
DBCC SHRINKFILE ('<db_name>_log2', EMPTYFILE)
go

Trouble is that I get the following error:

Server: Msg 1105, Level 17, State 2, Line 3
Could not allocate space for object '<company_name>. Inv. Line' in
database '<db_name>' because the 'Data Filegroup 1' filegroup is full.

As I understand you can only use EMPTYFILE to move data within a
filegroup, you cannot use it to move the data another file group.

To do this, you need to use CREATE CLUSTERED INDEX WITH DROP_EXISTING to
move the tables. Of course, you need to move non-clustered indes as well.
Please check Books Online, for the exact syntax.



--
Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
.



Relevant Pages

  • Re: Table Truncated (Urgent)
    ... My mdf file size 17 MB, ... Is there any way to retrive the data from LDF file. ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (microsoft.public.sqlserver.tools)
  • Re: Difference between multiple primary and secondary files..
    ... another 500GB disk to add to the PC) ... If you add another filegroup, you need to move objects, as objects ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)
  • Re: OLEDB connection string for .MDF (?)
    ... My question was about the possibility of using the standard SQL Server ... or SQL OleDb provider does not support .mdf files: ... The .mdf file is assumed to ... Books Online for SQL Server 2005 at ...
    (microsoft.public.data.oledb)
  • Re: Transform/transfer 50Gb - how to do it fast?
    ... But I'm afraid I then must create the newtbl first, ... But doesn't ALTER DATABASE permit you to specify a different filegroup as ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)
  • Re: Use MS SQL Server 2005 Developer version to open MDF file?
    ... analyzing SQL Server databases from outside shops. ... You don't really open an MDF file, but rather you attach it SQL Server, ... and then you can query it from a query tool. ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)