MSSQLWIKI

Karthick P.K on SQL Server

How to move the LOB data from one file group to other?

Posted by Karthick P.K on January 17, 2012

 

We do not have a direct way to move the LOB data from one file group to other. Using ALTER TABLE and/or CREATE INDEX to support moving LOB data is unavailable till current version of  SQL (SQL Server 2008).

 

Only way to move the LOB data is to

1. create new table in new file group

2. Move the data from existing table to new table.

3. Drop the existing table.

4. Change the name of new table to Old table.

Management studio has easy way to create script for all the above task.

1. In management studio Right click the table –>Design –>change the file group in properties windows (Click View—> properties window if you do not see properties window)

2. Generate Change Script.

clip_image002

3. Script similar to following script is generated.

4. Copy the script and run in Query window.

 

/* To prevent any potential data loss issues, you should review this script in detail before running it outside the context of the database designer.*/

BEGIN TRANSACTION

SET QUOTED_IDENTIFIER ON

SET ARITHABORT ON

SET NUMERIC_ROUNDABORT OFF

SET CONCAT_NULL_YIELDS_NULL ON

SET ANSI_NULLS ON

SET ANSI_PADDING ON

SET ANSI_WARNINGS ON

COMMIT

BEGIN TRANSACTION

GO

CREATE TABLE dbo.Tmp_BLOB_TABLE

                (

                BLOBName varchar(100) NULL,

                BLOBData varbinary(MAX) NULL

                )  ON [PRIMARY]

                TEXTIMAGE_ON Lob2

GO

ALTER TABLE dbo.Tmp_BLOB_TABLE SET (LOCK_ESCALATION = TABLE)

GO

IF EXISTS(SELECT * FROM dbo.BLOB_TABLE)

                EXEC(‘INSERT INTO dbo.Tmp_BLOB_TABLE (BLOBName, BLOBData)

                                SELECT BLOBName, BLOBData FROM dbo.BLOB_TABLE WITH (HOLDLOCK TABLOCKX)’)

GO

DROP TABLE dbo.BLOB_TABLE

GO

EXECUTE sp_rename N’dbo.Tmp_BLOB_TABLE’, N’BLOB_TABLE’, ‘OBJECT’

GO

COMMIT

 

Thanks

Karthick P.K

34 Responses to “How to move the LOB data from one file group to other?”

  1. Prashant said

    Nice post Karthick 🙂
    I am little confused with this statement though:
    “Using ALTER TABLE and/or CREATE INDEX to support moving LOB data is unavailable till current version of SQL (SQL Server 2008).”

    SQL 2008 onwards, can we move the LOB data to a different filegroup just by recreating indexes on the destination filegroup (without dropping table etc) ?

    • Hello Prashant,

      “Using ALTER TABLE and/or CREATE INDEX” to move LOB data is unavailable till current version of SQL (SQL Server 2008/2011 builds released till date). This option would most likely come in future.

      Thanks
      Karthick

      • Prashant said

        ok that is clear now 🙂

        For now, is there any other workaround so that we avoid dropping the table (and re-create etc) in order to move LOB data to a diff filegroup?

  2. sql user said

    Thank you Kartick, very useful information about this limitation, but how about other dependent objects, like indexes, statistics, triggers, foreign keys and other dependent objects on the table. I suppose every thing needs to be created manually and if we want to move multiple tables to another file groups, then it will become very complicated, especially with foreign keys.

    Is there is request raised with product team already on this? is there a connect item on this

  3. obviously like your web-site however you need to test the spelling on quite a few of your posts.
    Several of them are rife with spelling problems and I in
    finding it very bothersome to inform the
    reality on the other hand I’ll definitely come again again.

    • John Couch said

      How are a few minor spelling mistakes making it hard to read? The grammar in your comment is more unbearable than a few misspellings. If we could be so perfect.

      Karthick, thank you for teaching me yet 1 more thing I did not know. Incredibly helpful. THANKS!!

  4. […] How to move the LOB data from one file group to other? […]

  5. J’aі point terminé de lire mais jje passerai ce soir

  6. Jе vais fiknir de regarder tout ça dans la semaine

  7. sexe en hd said

    Un monumentɑl remerciement à l’auteur du site աeb

  8. Jе suis entièrement en accord аvec vous

  9. Je suuis entièrement du même avis que toi

  10. Splendiɗe postе : pour ne pas cɦanger

  11. Јe suis сlairement du même aviѕ quе toi

  12. Un ƿost plein de bons conseils

  13. Ϲ’est un véritable plaisir de regarder ce site

  14. Ѕujet rudement cultivant

  15. Jе vais dire գuue ce n’est ρas incohéгent …

  16. Јe vwis terminer ɗde lire tout cela plus tard

  17. Еst-il possible de ƿiquer 2 ou 3 phrfases pour un site internett perso
    ?

  18. test code gratuit

    How to move the LOB data from one file group to other? « MSSQLWIKI

  19. Meufs Sexy said

    Un articlе vraiment гrempli de maǥnifiques conseils

  20. Je terminerai de regɑrԀer ça ce soir

  21. Јe suis arrivée sur votre site web par chance et je ne
    le regrette point !!!

  22. On гemarque direct que vous connaissez superƅement bien ce que vous
    avancez

  23. Superbe ρoste encore une fois

  24. Tгès plaisant, je pense que ce post intéresserait mon ami

  25. Jе suis clairement enn accord avec vous

  26. On voit ɗirehtement quee vous connaissez bien le thème

  27. Puis-јe piquer 2 оuu 3 lignes pour mon site ?

  28. Je sսis сlairement d’accord avec toi

  29. Vous noսs concoctez toսjours ԁes articles passionnants

  30. […] have found following solution how-to-move-the-lob-data-from-one-file-group-to-other. Is there exists another […]

  31. I need a password sooo bad for this site…

    Salope Fontaine Join – http://www.salopefontaine.com/index.php?id=74327

    if you have any please email me at xxxadult56 [at] gmail.com

Leave a Reply to Karthick P.K Cancel 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 )

Facebook photo

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

Connecting to %s

 
%d bloggers like this: