SQL Server - 创建按顺序运行多个存储过程的存储过程 [英] SQL Server - create stored procedure that runs several stored procedures sequentially

查看:62
本文介绍了SQL Server - 创建按顺序运行多个存储过程的存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定这是否可行,但如果可行,我的方案将与它们来的一样简单.假设我有 6 个存储过程调用:

I'm not sure if this is possible but if so, my scenario would be about as simple as they come. Assuming I have 6 stored procedures called:

dbo.SyncSources
dbo.SyncData
dbo.UpdateStatistics
dbo.TruncateSourceTable
dbo.ValidateData
dbo.SearchData

它们都不需要输入任何变量,它们只需要按照上面出现的顺序执行即可.我可以创建一个存储过程来按顺序运行所有这些过程吗?请记住,该列表中的一些中间程序需要几个小时才能运行.此外,这是在 Azure 云数据库上,因此遗憾的是 SQL Server 代理不是一个选项.

None of them require any variables to be input, they simply need to be executed in the order in which they appear above. Can I create one stored procedure that will run all of them, sequentially? Keep in mind that some of the middle ones in that list take several hours to run. Also, this is on an Azure Cloud database, so SQL Server Agent is unfortunately not an option.

推荐答案

你可以试试这个

create procedure OneProcedureTorunThemAll

as
begin tran
exec dbo.SyncSources
exec dbo.SyncData
exec ...
commit

捕获错误、验证返回值等可能很好.

it could be nice to catch errors, verify return values, etc.

这篇关于SQL Server - 创建按顺序运行多个存储过程的存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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