if exists (select * from sysobjects where id = object_id('dbo.sp_Backup') and sysstat & 0xf = 4) drop procedure dbo.sp_Backup GO CREATE PROCEDURE sp_Backup AS declare @dbname varchar(50), @DeviceDump varchar(20), @dblast varchar (50) select @DeviceDump = 'Cinta' set nocount on /* --- Determino Ultima Base para hacer UNLOAD de la Cinta --- */ declare dblastcursor scroll cursor for select max(s.name) from sysdatabases s where s.name not in ('tempdb','pubs') open dblastcursor fetch next from dblastcursor into @dblast deallocate dblastcursor /* --- Recorro y dumpeo las bases de datos --- */ declare db scroll cursor for select s.name from sysdatabases s where s.name not in ('tempdb','pubs') open db fetch next from db into @dbname DUMP DATABASE @dbname TO @DeviceDump WITH NOUNLOAD, INIT, SKIP, STATS while (@@fetch_status = 0) begin fetch next from db into @dbname begin if (@@fetch_status = 0 and @dbname <> @dblast) DUMP DATABASE @dbname TO @DeviceDump WITH NOUNLOAD, NOINIT, SKIP, STATS end begin if (@@fetch_status = 0 and @dbname = @dblast) /* P/evitar que se haga dos veces la última */ DUMP DATABASE @dbname TO @DeviceDump WITH UNLOAD, NOINIT, SKIP, STATS end end deallocate db print " " print 'Se ha completado el Backup ...' print " " GO