如何在SQL Server中的多个数据库中执行存储过程 [英] how to execute stored procedure in multiple databases in sql server

查看:373
本文介绍了如何在SQL Server中的多个数据库中执行存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

如何在sql server中的多个数据库中执行存储过程

感谢

Hello,

how to execute stored procedure in multiple databases in sql server

thanks

推荐答案

解决方案1将适用于多个数据库中的多个存储过程.

为了使存储过程访问其他数据库,应将数据库链接起来.然后,使用名称中的数据库来访问该数据库中的表.
Solution 1 will work for multiple stored procedures in multiple databases.

For a stored procedure to access a different database the database should be linked. Then to access the tables in that database use the database in the name.
SELECT myColumn1 FROM [OtherServer\OtherInstance].[database].[schema].[table]


您可以执行以下操作:
You can do the following :
exec database1.dbo.usp_name1
exec database2.dbo.usp_name2
exec database3.dbo.usp_name3
-- continue like this as many times as you need


这篇关于如何在SQL Server中的多个数据库中执行存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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