N
N
nrv2017-04-14 17:28:48
SQL
nrv, 2017-04-14 17:28:48

Table backup automatically in MSSQL Server?

Hello.
Set the task to automate the execution of another task.
There was a backup of the tables (before the subsequent change), as follows:

select * into dwh2.REF.INTERNAL_ORG_ASSOC_backup_20170411 from dwh2.REF.INTERNAL_ORG_ASSOC

If you do not deviate from this method, you need to somehow feed the SQL Server with the table name generated automatically.
Is it possible?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Tsvetkov, 2017-04-14
@nrv

If you do not deviate from this method, you need to somehow feed the SQL Server the table name generated automatically.
Is it possible?
EXECUTE

A
Alexander, 2017-04-14
@NeiroNx

Yes, you can do something like this in a bat file, then add it to the task.

@echo off
mode con cp select=1251
for /f %%x in ('wmic path win32_localtime get /format:list ^| findstr "="') do set %%x
ECHO select * into dwh2.REF.INTERNAL_ORG_ASSOC_backup_%Year%%Month%%Day% from dwh2.REF.INTERNAL_ORG_ASSOC>"BackUp.sql"
ECHO GO>>"BackUp.sql"
ECHO [%date% %time%] Start BackUp >> "BackUp.log"
sqlcmd -E -d dwh2 -i "BackUp.sql" >> "BackUp.log"
DEL /F "BackUp.sql"
mode con cp select=866

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question