Return to Snippet

Revision: 12323
at March 10, 2009 19:09 by pollusb


Initial Code
-- ATTACH / DETACH
select 'exec sp_detach_db '''+rtrim(name)+'''' from sysdatabases where dbid > 4

-- Use script on source to attach on destination
select dbid*1000,name,'exec sp_attach_db '''+name+''',' from sysdatabases where dbid > 4
union all
select dbid*1000+fileid,db_name(dbid), ','''+rtrim(filename)+'''' 
from sysaltfiles where dbid > 4 
order by 1

Initial URL


Initial Description
I wrote that while working at CGI on Océ project in 2009-03.
This script will help you migrate DB from one server to another. You have to use the source server to generate the script for the destination server.

Initial Title
Detach and Attach all

Initial Tags


Initial Language
SQL