Dettach and Attach multi databases

  • Can some one please provide me the script to dettach and attach multiple databases? Please help

  • You could generate the detach statements via a query such as the following:

    select 'EXEC sp_detach_db ' + '''' + name + ''''

    from sys.databases

    where name like '%dbname%'

    The sp_attach_db statements (or create database .. for attach) can be generated in a similar way but you may need to take account of files that need to be put in different locations when they get attached

  • Thanks! can you please send me the whole attach script as well...

Viewing 3 posts - 1 through 2 (of 2 total)

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