USE [reddy]
GO
/****** Object: StoredProcedure [dbo].[usp_databasebackup] Script Date: 02/24/2011 22:37:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[usp_databasebackup] as
begin
declare @name varchar(max)
declare @path nvarchar(max)
declare @filedate varchar(max)
declare @filename varchar(max)
set @path='C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Backup\'
SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112)
declare cursor_db cursor for
select name from master..sysdatabases
where name not in('master','tempdb','model','msdb')
open cursor_db
fetch next from cursor_db into @name
while @@fetch_status=0
begin
set @filename =@path+@name+'_'+@filedate+'.BAK'
backup database @name to disk =@filename
fetch next from cursor_db into @name
end
close cursor_db
deallocate cursor_db
end
No comments:
Post a Comment