Wednesday, 4 May 2011

Stored Procedure for backup database in MS-SQL Server


In this stored procedure you have to send parameter to @path variable as your backup location.

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go


CREATE PROCEDURE [dbo].[sp_Database_Backup]
@path nvarchar(500)
AS
BEGIN


EXEC master.sys.xp_create_subdir @path
Set @path = @path + '\db_name.bak'
BACKUP DATABASE db_name
TO DISK = @path
  WITH FORMAT;
END

1 comment: