以特定顺序自动执行多个SQL Server 2012脚本 [英] Automate execution of multiple SQL Server 2012 scripts in specific order

查看:348
本文介绍了以特定顺序自动执行多个SQL Server 2012脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于从未使用过SQL Server 2012的任务,我需要一些指导.非常感谢您的帮助.我已经在SQL Server中继承了数据模型.

I needed some guidance with a task I have never worked with SQL Server 2012. Your help would be very much appreciated. I have inherited a data model in SQL Server.

基本上,我有5个SQL脚本:

Basically, I have 5 SQL scripts:

  1. 脚本A
  1. 脚本B
  2. 脚本C
  3. 脚本D
  4. 脚本E

要成功运行脚本B,它需要访问由脚本A生成的表才能执行计算.基本上,这些脚本是相互补充的.我需要按特定顺序运行脚本.

For running successfully script B,it needs access to tables generated by script A to perform calculation. Basically, the scripts are feeding each other. I need to run the scripts in a specific order.

我的第一个想法是存储过程".到目前为止,我过去只编写了一个存储过程来从同一脚本执行代码,而无需执行其他脚本.

My first idea was "stored procedure". So far, I have in the past only written a stored procedure to execute code from the same script that do not require executing other scripts.

我的问题是,对于以特定顺序自动执行上述5个脚本,您提出了哪些建议?我怎样才能做到这一点?您建议我这样做时会怎么想?

My question is, what are some ideas you propose for automatically executing the above 5 scripts in a specific order? how can I do this? What would you recommend me to think when doing this?

运行完整的脚本列表大约需要10个小时.

Running the complete list of scripts takes around 10 hours.

推荐答案

您可以轻松地创建一个新的SQL Server代理作业任务,如下所示:

You could easily create a new SQL Server Agent Job task like this:

  1. 展开"SQL Server代理"节点,然后右键单击作业"节点. SQL Server代理,然后选择新作业"

  1. 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.

将要运行的T-SQL命令粘贴到命令"窗口中 然后单击确定".

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.

按照您希望它们运行的​​顺序对每个脚本重复这些步骤.而且,你去了!

Repeat these steps for each scripts in the order you want them to run. And, there you go!

这篇关于以特定顺序自动执行多个SQL Server 2012脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆