是否可以通过SQL Server Management Studio自动执行MS SQL Server(2005)查询?

时间:2021-01-04 23:35:47

I have two queries saved on my SQL Server 2005 and I would like to have them running at certain intervals, e.g. every 24 hours. Is there a way to automate these queries and schedule them via SQL Server Management Studio?

我在SQL Server 2005上保存了两个查询,我希望它们以一定的间隔运行,例如每24小时一次。有没有办法自动化这些查询并通过SQL Server Management Studio安排它们?

6 个解决方案

#1


17  

You need to use the SQL Server Agent, installed as part of SQL Server. This is the background service that's responsible for running scheduled maintenance and backup tasks.

您需要使用作为SQL Server的一部分安装的SQL Server代理。这是后台服务,负责运行计划的维护和备份任务。

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

展开SQL Server Management Studio中的SQL Server代理节点,您应该看到一个名为“Jobs”的树节点

Right-clicking this will give you the option to add a new job. Jobs consist of a series of steps to be executed in order, and when you add a new step to your job, you can choose various types of step, including "Transact-SQL Script"

右键单击此选项将为您提供添加新作业的选项。作业包括按顺序执行的一系列步骤,当您向作业添加新步骤时,您可以选择各种类型的步骤,包括“Transact-SQL脚本”

Create a new job, add a single T-SQL step, put the queries that you want to run into the step properties, and then use the "Schedule" option in the Job properties to create a recurring schedule that'll run the job every 24 hours (or whenever).

创建一个新作业,添加一个T-SQL步骤,将要运行的查询放入步骤属性,然后使用“作业”属性中的“计划”选项创建一个定期执行每个作业的计划24小时(或每当)。

#2


1  

You can use the SQL Server Agent, which will allow the server to run the script/stored procedure.

您可以使用SQL Server代理,它将允许服务器运行脚本/存储过程。

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.

您还可以在服务器或任何其他服务器或工作站上使用Windows任务计划程序来安排isqlw / sqlcmd来执行脚本/存储过程。

#3


0  

Create a job with a step in which you execute your queries; the job can be scheduled at your needs.

创建一个包含执行查询的步骤的作业;可以根据您的需要安排工作。

#4


0  

At a previous employer the operations department had a task sheduling application. They prefered to use the command line tools that come with sql server to execute jobs (stored procedures) on a scheduled basis. This way the "task scheduling application" could recieve an exit status (pass/fail, ok/error) and hold up dependent jobs.

在以前的雇主,运营部门有一个任务调度应用程序。他们更喜欢使用sql server附带的命令行工具来按计划执行作业(存储过程)。这样,“任务调度应用程序”可以接收退出状态(通过/失败,确定/错误)并保持从属作业。

I'm sorry I don't remember the name of the command line tool, but it was part of the sql server distro. I also do not remember the name of the task scheduling application. It was not the windows task scheduler. It was something enterprise level used to manage the nightly cycle.

对不起,我不记得命令行工具的名称,但它是sql server发行版的一部分。我也不记得任务调度应用程序的名称。它不是Windows任务调度程序。这是企业级用于管理夜间循环的东西。

Not sure of the scale of your project, but this is another way to go.

不确定项目的规模,但这是另一种方法。

#5


0  

SKapsal's comment on a command line tool for executing SQL commands is a reference to osql (for SQL2000) or sqlcmd (for SQL2005+). You could save your script a file and run it from that command line using Windows Task Scheduler or something similar.

SKapsal对用于执行SQL命令的命令行工具的评论是对osql(对于SQL2000)或sqlcmd(对于SQL2005 +)的引用。您可以使用Windows任务计划程序或类似工具将脚本保存为文件并从该命令行运行它。

SQL Agent is still the preferred solution, however, as it provides GUI controls for job creation, scheduling, logging and viewing job execution history/results.

但是,SQL Agent仍然是首选解决方案,因为它为作业创建,调度,日志记录和查看作业执行历史记录/结果提供GUI控件。

#6


0  

how to schedule a job for sql query to run daily?

如何安排sql查询的作业每天运行?

This is similar question with helpful answer.

这是类似的问题,有用的答案。

Covering simple step by step manual.

涵盖简单的一步一步手册。

#1


17  

You need to use the SQL Server Agent, installed as part of SQL Server. This is the background service that's responsible for running scheduled maintenance and backup tasks.

您需要使用作为SQL Server的一部分安装的SQL Server代理。这是后台服务,负责运行计划的维护和备份任务。

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

展开SQL Server Management Studio中的SQL Server代理节点,您应该看到一个名为“Jobs”的树节点

Right-clicking this will give you the option to add a new job. Jobs consist of a series of steps to be executed in order, and when you add a new step to your job, you can choose various types of step, including "Transact-SQL Script"

右键单击此选项将为您提供添加新作业的选项。作业包括按顺序执行的一系列步骤,当您向作业添加新步骤时,您可以选择各种类型的步骤,包括“Transact-SQL脚本”

Create a new job, add a single T-SQL step, put the queries that you want to run into the step properties, and then use the "Schedule" option in the Job properties to create a recurring schedule that'll run the job every 24 hours (or whenever).

创建一个新作业,添加一个T-SQL步骤,将要运行的查询放入步骤属性,然后使用“作业”属性中的“计划”选项创建一个定期执行每个作业的计划24小时(或每当)。

#2


1  

You can use the SQL Server Agent, which will allow the server to run the script/stored procedure.

您可以使用SQL Server代理,它将允许服务器运行脚本/存储过程。

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.

您还可以在服务器或任何其他服务器或工作站上使用Windows任务计划程序来安排isqlw / sqlcmd来执行脚本/存储过程。

#3


0  

Create a job with a step in which you execute your queries; the job can be scheduled at your needs.

创建一个包含执行查询的步骤的作业;可以根据您的需要安排工作。

#4


0  

At a previous employer the operations department had a task sheduling application. They prefered to use the command line tools that come with sql server to execute jobs (stored procedures) on a scheduled basis. This way the "task scheduling application" could recieve an exit status (pass/fail, ok/error) and hold up dependent jobs.

在以前的雇主,运营部门有一个任务调度应用程序。他们更喜欢使用sql server附带的命令行工具来按计划执行作业(存储过程)。这样,“任务调度应用程序”可以接收退出状态(通过/失败,确定/错误)并保持从属作业。

I'm sorry I don't remember the name of the command line tool, but it was part of the sql server distro. I also do not remember the name of the task scheduling application. It was not the windows task scheduler. It was something enterprise level used to manage the nightly cycle.

对不起,我不记得命令行工具的名称,但它是sql server发行版的一部分。我也不记得任务调度应用程序的名称。它不是Windows任务调度程序。这是企业级用于管理夜间循环的东西。

Not sure of the scale of your project, but this is another way to go.

不确定项目的规模,但这是另一种方法。

#5


0  

SKapsal's comment on a command line tool for executing SQL commands is a reference to osql (for SQL2000) or sqlcmd (for SQL2005+). You could save your script a file and run it from that command line using Windows Task Scheduler or something similar.

SKapsal对用于执行SQL命令的命令行工具的评论是对osql(对于SQL2000)或sqlcmd(对于SQL2005 +)的引用。您可以使用Windows任务计划程序或类似工具将脚本保存为文件并从该命令行运行它。

SQL Agent is still the preferred solution, however, as it provides GUI controls for job creation, scheduling, logging and viewing job execution history/results.

但是,SQL Agent仍然是首选解决方案,因为它为作业创建,调度,日志记录和查看作业执行历史记录/结果提供GUI控件。

#6


0  

how to schedule a job for sql query to run daily?

如何安排sql查询的作业每天运行?

This is similar question with helpful answer.

这是类似的问题,有用的答案。

Covering simple step by step manual.

涵盖简单的一步一步手册。