Restore a Database using .mdf and .ldf

  • Hi,

    One of our customer servers has crashed. they are unable to restore the c:\ drive from backup (this drive included SQL system files) but all SQL datafiles were on d:\ and are still available. SQL Server is no longer on the server. Is there are way to restore / attach the datafiles to another SQL server? these databases were not detached at the the time of the crash. I take it i cant use sp_attach, does anyone know of another method

    cheers,

    Shaun

  • It should be possible to attach the files. The 2005 replacement for sp_attach is CREATE DATABASE .... FOR ATTACH

    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
  • You mentioned "system files". I'm not sure if you meant SQL binaries or system databases?

    If you meant your system databases were also on C then you'll need to recreate your logins and permissions as well if you have no backups of the master database.

    Not forgetting any jobs which may be lost if you have no msdb...

  • Also, where are the backups of all these databases?

    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
  • It sounds like you need to:

    - install SQL Server

    - attach the databases

    - rebuild logins if you cannot attach master.

  • thanks for the replies, master database data files are on d:\ as well. i meant SQL installation files etc were all lost.

    i need to install SQL server 2000 again. Can i just attach master, tempdb, model etc as well.

    what i was thinking might be the best if i can attached the client application databases and recreate the login there'll be no need to attach the master etc - does this sound right?

  • Sure, if you only have a few logins / databases etc in the master database, then yes, you can attach your client database and quickly add the logins back in manually.

  • Forgot to mention, once you have added the login back in, if you try to add the user, you'll likely get a message telling you the user already exists in database X.

    You'll need to run the following in the attached database:

    sp_change_users_login 'auto_fix', 'UserName'

    This will fix the login/user mapping for you and retain the original permissions.

  • Master is a parameter in the service startup, so what you'd do it make you have a copy of your current files. Install SQL, then change the startup parameter to point to your old master database.

    You don't need to worry about tempdb or model (or shouldn't). Never tried attaching msdb, but I'm sure it can be done.

  • thanks guys, i'll give it a go

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

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