declare @Backup_file char(40)
declare @flag int
declare @rows int
set @flag = day(getdate()) % 2
if @flag = 1
begin
set @Backup_file = 'D_数据库名_单日备份'
print '数据库名_单日备份'
end
else
begin
set @Backup_file = 'D_数据库名_双日备份'
print '数据库名_双日备份'
end
checkpoint
dbcc checkdb
dbcc checkalloc
dbcc checkcatalog
backup database 数据库名 to @Backup_file with init
select @rows = count(backup_device) from ut_database_backup_log
where backup_device = @backup_file
if @rows = 0
insert ut_database_backup_log values (getdate(), '数据库名', @backup_file, null)
else
update ut_database_backup_log set backup_date = getdate() where backup_device = @backup_file
select * from ut_database_backup_log
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO