开发者

how to pass all database (fast) since sql server 2008 express to sql server 2008 R2 (NO express)

well i had sql 2008 express, and now i have installed, sql server, now i want to delete sql express, but in that instance i have all my database i have worked (plus of 20), so they are very important for me, how can i pass it to sql server 2008 r2, i know i can do database of all开发者_如何学JAVA but i dont want to work a lot of, there is a way short, for to pass al database? coping a folder? something? thanks!


I Attached all database, and i added, all (but one for one) i added all in the same windows and in 5 minutos i had all database in sql (no express)


Create an SSIS package with 4 steps.

First, a Execute SQL task that backups all DBs to a specific location:

exec sp_msforeachdb '
IF DB_ID(''?'') > 4
Begin
BACKUP DATABASE [?] TO  DISK = N''\\Backups\?.BAK'' WITH NOFORMAT, INIT,
NAME = N''?-Full Database Backup'', SKIP, NOREWIND, NOUNLOAD
declare @backupSetId as int
select @backupSetId = position from msdb..backupset where database_name=N''?''
    and backup_set_id=(select max(backup_set_id) from msdb..backupset 
where database_name=N''?'' )
if @backupSetId is null begin
    raiserror(N''Verify failed. Backup information for database ''''?'''' not found.'', 16, 1)
end
RESTORE VERIFYONLY FROM  DISK = N''\\Backups\?.BAK'' WITH
   FILE = @backupSetId,  NOUNLOAD,  NOREWIND
End
'

Second, Create a SP to restore DBs using a variable for location and DB name:

CreatePROCEDURE [dbo].[uSPMas_RestoreDB] @DBname         NVARCHAR(200), 
                                         @BackupLocation NVARCHAR(2000) 
AS 
  BEGIN 
      SET nocount ON; 

    create table #fileListTable 
(
    LogicalName          nvarchar(128),
    PhysicalName         nvarchar(260),
    [Type]               char(1),
    FileGroupName        nvarchar(128),
    Size                 numeric(20,0),
    MaxSize              numeric(20,0),
   )
insert into #fileListTable EXEC('RESTORE FILELISTONLY FROM DISK = '''+@BackupLocation+@dbname+'.bak''')

Declare @Dname varchar(500) 
Set @Dname = (select logicalname from #fileListTable where type = 'D')
Declare @LName varchar(500)
Set @LName = (select logicalname from #fileListTable where type = 'L')

declare @sql nvarchar(4000)
SET @SQL = 'RESTORE DATABASE  ['+ @dbname +'] FROM  
DISK = N'''+@BackupLocation + @dbname +'.BAK'' WITH  FILE = 1, 
 MOVE N'''+ @Dname +''' TO N''E:\YourLocation\'+ @dbname +'.mdf'', 
 MOVE N'''+ @LName +''' TO N''D:\Your2ndLocation\'+ @dbname +'_log.ldf'',
  NOUNLOAD,  REPLACE,  STATS = 10'

exec sp_executesql @SQL 

drop table #fileListTable
  END 

Third, Create a ForEach Loop Container and put a Execute Sql Statement with variable:

EXEC uSPMas_RestoreDB ? , ?

Use the for ForEach Loop Container to pass the variables

Fourth, Create a 'Transfer Logins' task to move over all DB logins

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜