Skip to content

Instantly share code, notes, and snippets.

@bmatzelle
Created February 19, 2014 16:38
Show Gist options
  • Save bmatzelle/9095820 to your computer and use it in GitHub Desktop.
Save bmatzelle/9095820 to your computer and use it in GitHub Desktop.
Example of how to backup a table with SQL for SQL Server
DECLARE @dbName varchar(1000);
DECLARE @exportPath varchar(1000);
SET @exportPath = 'C:\Database_Backups';
SET @dbName = 'YourDatabase';
-- Backs up data in the format: "[DB_name]_YYYY.MM.DD.bak"
SET @exportPath = @exportPath + '\' + @dbName + '_' +
(SELECT CONVERT(VARCHAR(12), GETDATE(), 102)) + '.bak';
BACKUP DATABASE @dbName TO DISK = @exportPath;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment