drop proc proc_AddDB
go
go
--通过SQL自动附加满足一定规则的数据库
create proc proc_AddDB
(
@DBStartIndex int,
@CreateDBCount int,
@BackFileFilePath varchar(50),
@BackFileDBName varchar(50)
)
asdeclare @currentIndex int
declare @cmd varchar (1024)
declare @CurrentDBNumber varchar
declare @DBFullPathPrefix varcharset @currentIndex=0
while @currentIndex<@CreateDBCount
begin
set @CurrentDBNumber = cast((@currentIndex+@DBStartIndex) as varchar)
set @DBFullPathPrefix = @BackFileFilePath+'/'+@BackFileDBNameSet @Cmd = 'sp_attach_db DBMydbName_'+@CurrentDBNumber+','+@DBFullPathPrefix+@CurrentDBNumber+'_Data.Mdf'+','+@DBFullPathPrefix +@CurrentDBNumber+'_Log.ldf'
set @currentIndex=@currentIndex+1;
end
EXEC (@Cmd)
go
create proc proc_AddDB
(
@DBStartIndex int,
@CreateDBCount int,
@BackFileFilePath varchar(50),
@BackFileDBName varchar(50)
)
asdeclare @currentIndex int
declare @cmd varchar (1024)
declare @CurrentDBNumber varchar
declare @DBFullPathPrefix varcharset @currentIndex=0
while @currentIndex<@CreateDBCount
begin
set @CurrentDBNumber = cast((@currentIndex+@DBStartIndex) as varchar)
set @DBFullPathPrefix = @BackFileFilePath+'/'+@BackFileDBNameSet @Cmd = 'sp_attach_db DBMydbName_'+@CurrentDBNumber+','+@DBFullPathPrefix+@CurrentDBNumber+'_Data.Mdf'+','+@DBFullPathPrefix +@CurrentDBNumber+'_Log.ldf'
set @currentIndex=@currentIndex+1;
end
EXEC (@Cmd)
go