日期:2014-05-18 浏览次数:20549 次
USE test DECLARE @DBName VARCHAR(100) , @DBName2 VARCHAR(100) DECLARE @ym VARCHAR(6) , @ym2 VARCHAR(6) DECLARE @msg VARCHAR(100) , @msg2 VARCHAR(100) DECLARE @BackupFile VARCHAR(100) , @BackupFile2 VARCHAR(100) DECLARE @BackName VARCHAR(100) , @BackName2 VARCHAR(100) DECLARE @Stats VARCHAR(2) SET @DBName2 = N'AdventureWorks' SET @ym2 = Convert(char(6),getdate() ,112) SET @ymd2 = Convert(char(8),getdate() ,112) SET @msg2 = N'''验证失败。找不到数据库' + @DBName2 + '的备份信息。''' SET @BackupFile2 = N'''E:\FULL\' + @DBName2 + '_' + 'full' + '_' + @ym2 + '.bak''' SET @BackName2 = N'''' + @DBName2 + '_' + 'full' + '_' + '''' SET @DBName = @DBName2 SET @ym = @ym2 SET @ymd = @ymd2 SET @msg = @msg2 SET @BackupFile = @BackupFile2 SET @BackName = @BackName2 SET @Stats = 10 EXECUTE ('BACKUP DATABASE' + ' ' + '[' + @DBName + ']' + ' ' + 'TO DISK =' + @BackupFile + ' ' + 'WITH' + ' ' + 'NOFORMAT' + ',NOINIT' + ',NAME =' + @BackName + ',SKIP' + ',NOREWIND' + ',NOUNLOAD' + ',STATS =' + ' ' + @Stats + ',CHECKSUM') DECLARE @backupSetId AS INT SELECT @backupSetId = position FROM msdb..backupset WHERE database_name = @DBName AND backup_set_id = (SELECT MAX(backup_set_id) FROM msdb..backupset WHERE database_name = @DBName ) IF @backupSetId IS NULL BEGIN raiserror(@msg, 16, 1) END RESTORE VERIFYONLY --------------这行开始报错 FROM DISK = @BackupFile WITH CHECKSUM , STOP_ON_ERROR , FILE = @backupSetId, NOUNLOAD , NOREWIND