到还原磁盘:'+@Drive+N' ,或者磁盘剩余空间小于1G'
RAISERROR50001@errorinfo
set@ResultCount=0
return
end
end
elseif(LEN(@RestoreDataPath)>1) ANDCHARINDEX(':',@RestoreDataPath)=0
begin
set@errorinfo=N'还原路径错误:'+@RestoreDataPath+N',必须包含":" 号'
Raiserror50001@errorinfo
set@ResultCount=0
return
end
set@ResultCount=1
end
GO
还原单个数据库:
Usemaster
GO
/*=================Usp_RestoreDataBaseFormPath=======================================
=====Restore Single DataBase From a Back File ======
=====Ken.Guo ======
=====2010.9.10 ======
=====Version: 2005 & 2008 SQL Server ======
=====Usp_RestoreDataBaseFormPath 'D:\databack\dbcenter.bak','D:\Data',0 ======
=====Key Point Info: ======
--Restore HeaderOnly from disk='D:\data\xx.bak'
--Restore FileListOnly from disk='D:\data\xx.bak'
===================================================================================
*/
CREATEPROCUsp_RestoreDataBaseFormPath
(@DatabBaseBakPathnvarchar(400),
@RestoreDataPathnvarchar(400)='', --RESTORE DATABASE PATH
@IsRunsmallint=0-- 0 PRINT 1 run
)
AS
BEGIN
setnocount on
declare@dbnamenvarchar(200),@SQLnvarchar(4000),@DirSQLnvarchar(1000),@errorinfonvarchar(300)
--add path \
if(@RestoreDataPathisnotnull) andlen(@RestoreDataPath)>1
and(right(@RestoreDataPath,1)<>'\')
set@RestoreDataPath=@RestoreDataPath+'\'
declare@checkdriveint
set@checkdrive=1
execmaster.dbo.Usp_Check_DriveExists @RestoreDataPath,@checkdriveoutput
if(@checkdrive<>1)
GotoExitFLag
DECLARE@BakFileListTABLE
( LogicalName nvarchar(128)
,PhysicalName nvarchar(260)
)
DECLARE@BakHeaderInfoTABLE
(
DatabaseName nvarchar(128)
)
ifCharindex('Microsoft SQL Server 2008',@@VERSION)>0
begin
--SQL Server 2008
DECLARE@BakFileList2008TABLE
( LogicalName nvarchar(128)
,PhysicalName nvarchar(260)
,Type char(1)
,FileGroupName nvarchar(128)
,SIZE numeric(20,0)
,MaxSize numeric(20,0)
,FileID bigint
,CreateLSN numeric(25,0)
,DropLSN numeric(25,0) NULL
,UniqueID uniqueidentifier
,ReadOnlyLSN numeric(25,0) NULL
,ReadWriteLSN numeric(25,0) NULL
,BackupSizeInBytes bigint
,SourceBlockSize int
,FileGroupID int
,LogGroupGUID uniqueidentifierNULL
,DifferentialBaseLSN numeric(25,0) NULL
,DifferentialBaseGUID uniqueidentifier
,IsReadOnly bit
,IsPresent bit
,TDEThumbprint varbinary(32)
)
INSERTINTO@BakFileList2008
EXECsp_executesql N'Restore FileListOnly From Disk=@DatabBaseBakPath',N'@DatabBaseBakPath nvarchar(260)',@DatabBaseBakPath
DECLARE@BakHeaderInfo2008TABLE
(
BackupName nvarchar(128)
,BackupDescription nvarchar(255)
,BackupType smallint
,ExpirationDate datetime
,Compressed tinyint
,POSITION smallint
,DeviceType tinyint
,UserName nvarchar(128)
,ServerNam