attach all dbs in a folder

  • I had to reinstall SQL server 2008 back on a server and have about 30 db's in a directory that need reattaching. Does anyone have a routine or script that will go to a specific folder and reattach all db's in that folder?

  • GrassHopper (7/8/2013)


    I had to reinstall SQL server 2008 back on a server and have about 30 db's in a directory that need reattaching. Does anyone have a routine or script that will go to a specific folder and reattach all db's in that folder?

    As I see it... databases have to be recreated then attach data files which might or might not be a nightmare depending on naming convention, number of data files per database, etc.

    Wouldn't be easier to restore the databases instead?

    _____________________________________
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at Amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
  • You should have created attach script BEFORE detaching databases. If you still have backup of master database, restore it somewhere under different name, and create "ATTACH" script by joining sys.databases and sys.master_files

  • Would this help?

    http://www.sqlservercentral.com/scripts/96623/

  • thanks but this is good for an existing server instance and not a new one with db's that are unattached. There is no history in the master db of these db's.

  • Are all databases going back to the same pathing? Or to the default paths on the new server?

  • Same path. The db's remain in the same location.

  • I think this will help. I can't test right now, but it looks like it reads the files, gets the info from them, and then builds the restore command.

    http://www.sqlservercentral.com/scripts/Backup+%2F+Restore/30962/

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

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