SQL SERVER2012中使用遊標來備份數據庫

在SQL SERVER中,添加JOB,可使用如下語句設置按期備份數據庫。數據庫

DECLARE @name VARCHAR(50)--databasenameget

DECLARE @path VARCHAR(256)--pathforbackupfilesast

DECLARE @fileName VARCHAR(256)--filenameforbackupsed

DECLARE @fileDate VARCHAR(20)--usedforfilename SET @path='E:\Backup' SELECT @fileDate=CONVERT(VARCHAR(20),GETDATE(),112)file

DECLARE db_cursor CURSOR FOR  SELECT [name]  FROM master.dbo.sysdatabases  WHERE [name] NOT IN('master','model','msdb','tempdb')  model

OPEN db_cursor  FETCH NEXT FROM db_cursor INTO @name  WHILE @@FETCH_STATUS=0  數據

BEGIN   rbac

SET @fileName=@path+@name+'_'+@fileDate+'.BAK'  db

BACKUP DATABASE @name TO DISK=@fileName  tab

FETCH NEXT FROM db_cursor INTO @name  

END  CLOSE db_cursor  

DEALLOCATE db_cursor

-----------------------

DECLARE @name VARCHAR(50)--databasename

DECLARE @path VARCHAR(256)--pathforbackupfiles

DECLARE @fileName VARCHAR(256)--filenameforbackup

DECLARE @fileDate VARCHAR(20)--usedforfilename SET @name='dbname' SET @path='E:\' SELECT @fileDate=CONVERT(VARCHAR(20),GETDATE(),112) SET @fileName=@path+@name+'_'+@fileDate+'.BAK' BACKUP DATABASE @name TO DISK=@fileName ------------------------

相關文章
相關標籤/搜索