Can I just attach to a database?

  • My work PC had a very small primary drive. My boss was able to get larger drives. This morning my PC's primary drive was replaced and now I'm installing SQL Server 2016 Developer Edition SP1.

    However, I made one mistake. I didn't detach any of the databases I had on it. (I put all of my databases onto a secondary drive that the PC has.) I can see them in File Explorer (I'm using Windows 10 Enterprise), so the .mdf and .ldf ffiles are there. Can I just attach to them and that will be enough?

    Kindest Regards, Rod Connect with me on LinkedIn.

  • Did you properly shut down the operating system before having the primary drive replaced?  If so, SQL Server would have shut itself down and there shouldn't be any problems.  If not, I don't know.  You can always make backup copies of the files and try attaching to the original.

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

  • As has been said it depends on whether your SQL Server services shutdown cleanly. If not there are ways to attach a single file as a database, but it will rebuild the log and that will mean you may have consistency issues in the database, but you should still be able to attach them.



    Ben Miller
    Microsoft Certified Master: SQL Server, SQL MVP
    @DBAduck - http://dbaduck.com

  • This was removed by the editor as SPAM

  • Hi,
    if your LDF-File is crashed, you can attach a database without ldf file.

    It  is hard and tricky, but it is possible:

    http://www.enabledbusinesssolutions.com/blog/attaching-a-database-mdf-file-when-the-ldf-file-is-missing-with-a-catch/

    I had to do this one time, because our LDF-File was crashed during shutodown, and we were not able to attach on the "normal" way.

    Best regards,

    Andreas

  • sgmunson - Tuesday, March 7, 2017 1:35 PM

    Did you properly shut down the operating system before having the primary drive replaced?  If so, SQL Server would have shut itself down and there shouldn't be any problems.  If not, I don't know.  You can always make backup copies of the files and try attaching to the original.

    Yes, I did an orderly shutdown of my PC. This is good to know sgmunson, thanks.

    Kindest Regards, Rod Connect with me on LinkedIn.

  • just to clarify, it's not a case of whether the instance was shutdown cleanly, but whether the database itself was shut down cleanly.
    A clean system shutdown is a good start though

    -----------------------------------------------------------------------------------------------------------

    "Ya can't make an omelette without breaking just a few eggs" 😉

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

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