复制代码 代码如下:
CREATE PROCEDURE CopyDB
(
@newDbName varchar(50), --新数据库名称
@dbDataDirPath varchar(100), --数据库安装的Data文件夹目录路径
@soureDbName varchar(100), --源数据库名称
@soureBackupFilePATH varchar(100)--源数据库备份文件的路径
)
AS
declare @sql varchar(3000)
set @sql='
create database '+@newDbName+'
ON
(
name='+@soureDbName+'_Data,
filename='''+@dbDataDirPath+@newDbName+'_Data.mdf'',
SIZE = 10,
FILEGROWTH = 15%
)
LOG ON
(
name='''+@soureDbName+'_Log'',
filename='''+@dbDataDirPath+@newDbName+'_Log.LDF'',
SIZE = 5MB,
MAXSIZE = 25MB,
FILEGROWTH = 5MB
)
--开始还原
RESTORE DATABASE '+@newDbName+' from disk='''+@soureBackupFilePATH+''' WITH REPLACE
'
exec(@sql)
GO
新闻热点
疑难解答