Recover corrupted database

  • I am facing a situation like this:
    I some ndf files deleted accidentally and the latest backup refers to yesterday
    I create the same database and overwrite main database files on new one.
    then :

    ALTER DATABASE [MyDb] SET EMERGENCY;
    GO
    ALTER DATABASE [MyDb] SET SINGLE_USER;
    GO
    DBCC CHECKDB (N'MyDb', REPAIR_ALLOW_DATA_LOSS) WITH NO_INFOMSGS, ALL_ERRORMSGS;

    but I gave this error :
    One or more files do not match the primary file of the database. If you are attempting to attach a database, retry the operation with the correct files. If this is an existing database, the file may be corrupted and should be restored from a backup.

    How can I recover this database?

  • Do you take log backups? If you have your full backup from yesterday then restore your logs up to the point where the data files were deleted.

    Thanks

  • If files that are part of the database (the NDFs) were actually deleted, your only option is to restore from backup.  That's not "corruption" such as can be (potentially, often with data loss) repaired.

    As NorthernSoul asked, if you take log backups, you can at least recover up to close to the time the NDFs were deleted.

  • I don't know how you deleted your NDFs accidentally, but if you did so on the server, check the recycle bin.  I know it sounds simple, but we don't know what happened except for what you tell us.  You might just get lucky with this one.

    If you don't have the files themselves, then restore from backup like others have said.

  • This was removed by the editor as SPAM

  • farax_x - Tuesday, October 17, 2017 4:48 AM

    How can I recover this database?

    Restore from backup.  You cannot mix and match data files.
    If the DB is in full recovery, you can take a tail-log backup and lose nothing. If it's in simple, you'll lose data back to the last full backup.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 6 posts - 1 through 5 (of 5 total)

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