/ Published in: SQL
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.
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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
-- 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