:: Delete the Temporary SQL File
IF EXIST "backup.sql" DEL "backup.sql"
echo set nocount on >> "backup.sql"
echo declare @sql varchar(255) >> "backup.sql"
echo declare @backup_path varchar(255) >> "backup.sql"
echo set @backup_path='C:' >> "backup.sql"
echo declare c100 cursor for >> "backup.sql"
echo select convert(varchar(255), 'use '+name+' exec sp_helpdb '+name+' dbcc checkdb('''+name+''') backup database '+name+' to disk='''+@backup_path+'\'+name+'-1.bak''') >> "backup.sql"
echo from master..sysdatabases >> "backup.sql"
echo where name in ('MyDB') >> "backup.sql"
echo order by name >> "backup.sql"
echo open c100 >> "backup.sql"
echo fetch c100 into @sql >> "backup.sql"
echo while @@fetch_status = 0 begin >> "backup.sql"
echo print '' >> "backup.sql"
echo print @sql >> "backup.sql"
echo print '' >> "backup.sql"
echo exec(@sql) >> "backup.sql"
echo fetch c100 into @sql >> "backup.sql"
echo end >> "backup.sql"
echo; >> "backup.sql"
echo close c100 >> "backup.sql"
echo deallocate c100 >> "backup.sql"
ECHO Database Backup is in progress
ECHO Please wait...........