Can I automate MS SQL Server (2005) queries through SQL Server Management Studio?

I have two queries stored on my SQL Server 2005, and I would like them to run at regular intervals, for example. every 24 hours. Is there a way to automate these queries and schedule them through SQL Server Management Studio?

+4
source share
6 answers

You need to use the SQL Server Agent installed as part of SQL Server. This is a help desk that is responsible for performing scheduled maintenance and backup tasks.

Expand the SQL Server node agent in SQL Server Management Studio, you will see a node tree called "Jobs"

When you right-click, this will give you the opportunity to add a new task. Tasks consist of a sequence of steps that must be performed in order, and when you add a new step to your task, you can select various types of steps, including "Transact-SQL Script"

Create a new task, add one T-SQL step, place the queries you want to run in the properties of the step, and then use the Schedule parameter in the task properties to create a repeating schedule that will run every 24 hours (or every time )

+17
source

You can use the SQL Server agent, which allows the server to run the script / stored procedure.

You can also use the Windows task scheduler, either on the server or on any other server or workstation, to schedule isqlw / sqlcmd to execute your script / stored procedure.

+1
source

Create a task with a step at which your requests are executed; work can be scheduled according to your needs.

0
source

The previous employer in the operations department had a task planning application. They preferred to use the command line tools that come with the sql server for scheduled tasks (stored procedures). Thus, the "task scheduling application" can receive exit status (pass / fail, ok / error) and delay dependent tasks.

Sorry, I don’t remember the name of the command line tool, but it was part of the sql server distribution. I also do not remember the name of the application for scheduling tasks. It was not a Windows task scheduler. An enterprise level was used to control the night cycle.

Not sure about the scope of your project, but this is another way.

0
source

The SKapsal comment in the command line tool for executing SQL commands is a reference to osql (for SQL2000) or sqlcmd (for SQL2005 +). You can save the script file and run it from this command line using the Windows Task Scheduler or something similar.

The SQL agent is still the preferred solution because it provides GUI controls for creating jobs, scheduling, logging, and viewing execution history / results.

0
source

How to schedule a task for an SQL query to run daily?

This is a similar question with a helpful answer.

Coverage of a simple walkthrough.

0
source

Source: https://habr.com/ru/post/1277605/


All Articles