Last post Mar 15, 2019 02:57 AM by Wei Zhang
Mar 14, 2019 11:47 AM|thepast|LINK
hi people I wrote this code to backup my database
DECLARE @filename varchar(100);
DECLARE @dbname varchar(100);
DECLARE @filedate varchar(20);
set @filename='D:\mm Backup\';
set @filedate= CONVERT(varchar(10),getdate(),105);
set @filename=@filename + @dbname + '-' + @filedate + '.bak';
backup database @dbname to disk= @filename;
I want to put it in .bat file to schedule it and run it at 8:00 PM everyday
How can I make that
Mar 14, 2019 01:13 PM|mgebhard|LINK
As recommend in your similar thread, use osql or cmdsql to execute SQL via the command line.
Simply save the text file as a filename.bat and execute the bat file using Windows Task Scheduler or SQL agent.
Mar 15, 2019 02:57 AM|Wei Zhang|LINK
According to your description, if you want to run query daily and set the time , I suggest you that you could create the schedule for the sql jobs. Sqlserver will do the job by following the schedule.You could follow the steps as below:
Expand the SQL Server Agent node and right click the Jobs node in SQL Server Agent and select 'New Job'
In the 'New Job' window enter the name of the job and a description on the 'General' tab.
Select 'Steps' on the left hand side of the window and click 'New' at the bottom.
In the 'Steps' window enter a step name and select the database you want the query to run against.
Paste in the T-SQL command you want to run into the Command window and click 'OK'.
Click on the 'Schedule' menu on the left of the New Job window and enter the schedule information (e.g. daily and a time).
Click 'OK' - and that should be it.
Here is the link, I hope it could help you.