How to delete an offline datafile

  • Hello all

    I really need to remove some data files, but they are offline and the commands that I know required the file to be online, the problem is that they are corrupted so i can set them online again

    Is there any way to achieve this?

    Thanks in advance

  • Can you detach them? That should allow you to delete them.

    What have you tried?

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • The db consists of 4 datafiles and 1 log, two valid and two invalid( the offline ones ) I tried this

    USE [database]

    GO

    ALTER DATABASE [database] REMOVE FILE [corruptedfile]

    GO

    ALTER DATABASE [database] REMOVE FILEGROUP [myfilegroup]

    GO

    and I receive:

    Msg 5056, Level 16, State 2, Line 1

    Cannot add, remove, or modify a file in filegroup 'myfilegroup' because the filegroup is not online.

  • Can you detach them?

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • how?

  • First detach the file:

    http://msdn.microsoft.com/en-us/library/ms188031.aspx

    Then you should be able to delete the data and log files.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • But that detach the whole db not only the files, if i delete the files i'll be able to attach the db again? I need to be sure since this is a prod db

  • Maybe I missed the intent of your question...I thought you wanted to purge the database and its (physical) data files from the server...but now I am thinking that you just want to remove some of the (logical) data files from the database definition itself and absorb whatever data loss that carries with it so you can bring the database online. Can you confirm that is the intent of your original post?

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • exactly

  • Sorry...that I do not have info on. I did find this though:

    http://social.msdn.microsoft.com/forums/en-US/sqldatabaseengine/thread/ffd1787b-5c5a-4824-b049-925a604bcb61/[/url]

    It has some links to other articles but nothing that seemed like it had a concrete solution.

    Total guess here...but can you backup the database? Maybe you can do a backup followed by a piecemeal restore. The metadata would still be in your database but it would rid you of the physical files associated with the bad logical files/filegroups.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

Viewing 10 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic. Login to reply