Note: This applies to Microsoft SQL Server 2005/2008... Ever get sick of having a different SQL Job for each database backup? I created this method for backing up all databases (filtered) in a cursor. Just create a job with this as the Step and give the Job a schedule... 01: DECLARE @dbName varchar (50) 02: DECLARE @BKPDate varchar (10) 03: DECLARE @sql nvarchar (1000) 04: SET @BKPDate = replace ( convert ( varchar (10), getdate (), 102), '.' , '' ) 05: DECLARE bkpCursor CURSOR FOR 06: 07: /* only backup non-system databases */ 08: select [Name] from sys.databases where [owner_sid] <> 0x01 09: 10: OPEN bkpCursor 11: FETCH NEXT FROM bkpCursor INTO @dbName 12: IF @@FETCH_STATUS = 0 13: BEGIN 14: WHILE ( @@FETCH_STATUS = 0) 15: BEGIN 16: set @sql = 17: ' BACKUP DATABASE ' + @dbName + 18: ' TO
Comments