Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Dettach and Attach multi databases Expand / Collapse
Author
Message
Posted Wednesday, June 26, 2013 12:21 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Tuesday, February 18, 2014 8:31 AM
Points: 236, Visits: 934
Can some one please provide me the script to dettach and attach multiple databases? Please help
Post #1467808
Posted Wednesday, June 26, 2013 3:20 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 5:48 AM
Points: 2,717, Visits: 2,339
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
Post #1467889
Posted Thursday, June 27, 2013 2:35 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Tuesday, February 18, 2014 8:31 AM
Points: 236, Visits: 934
Thanks! can you please send me the whole attach script as well...
Post #1468348
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse