如果E驱动器可用空间低于50 GB,则必须移动G驱动器。再次,如果E和G驱动器的可用空间是<= 50 GB,那么它必须具有下一个可用驱动器。 条件:驱动器名称不固定,备份不应该转到C盘。
create table #Space(Drive varchar(4),SpaceAvailable varchar(15)) 插入#Space(Drive,SpaceAvailable) exec xp_fixeddrives
Alter table #Space add FinalSpace as spaceavailable/1024
select * from #Space
Declare @FreeSpace int=0
select @FreeSpace=(select top 1 FinalSpace from #Space)
print @FreeSpace
if (@FreeSpace between 0 and 50)
begin
print 'No Space Available'
end
if (@FreeSpace between 51 and 124 )
begin
backup database PerfDB to disk='E:\PerfDB.bak' -- Here E drive should change to G OR F OR H drives
Print 'Loop Entered to E'