Skip to content

Instantly share code, notes, and snippets.

@FilipDeVos
Created January 21, 2015 11:04
Show Gist options
  • Save FilipDeVos/b08790b78b75fa202bc8 to your computer and use it in GitHub Desktop.
Save FilipDeVos/b08790b78b75fa202bc8 to your computer and use it in GitHub Desktop.
if object_id(N'p_create_backup') is null
exec('create procedure p_create_backup as return (-1)')
GO
alter procedure p_create_backup (@BackupPath nvarchar(266), @Database sysname)
as
declare @fileName nvarchar(266) = @Database + N'.bak'
, @safeDatabase nvarchar(258) = quotename(@Database)
, @fileFullPath nvarchar(266) = @BackupPath + @fileName
-- validate filepath here; too lazy atm
exec (N'BACKUP DATABASE ' + @safeDatabase + ' TO DISK = ''' + @fileFullPath + N'''')
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment