I have a stored procedure hello
which generates a table. I want to take the backup of that table every week using sql job. Can someone tell me a command for that.
So far I have tried to take a backup of an existing table employee
in database emp
using the command:
DECLARE @table VARCHAR(128),
@file VARCHAR(255),
@cmd VARCHAR(512)
SET @table = 'dbo.employee' -- Table Name which you want to backup
SET @file = 'C:\Users\vibhav.sarraf\Documents\New_folder\' + @table + '_' + CONVERT(CHAR(8), GETDATE(), 112)
+ '.dat'
SET @cmd = 'bcp ' + @table + ' out ' + @file + ' -n -T '
EXEC emp..xp_cmdshell @cmd
which generates a 0 Byte file with and gives an error:
Error
[Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid object name 'dbo.employee'.
which I think is because I am not using use emp;
Note:- I dont want to create any table in my database