是否可以在另一个数据库中调用一个数据库的函数和存储过程-Azure Sql Server

问题描述:

我需要从另一个数据库向Azure sql中的数据库调用函数.那是 , DB1中有一个功能.我在DB2中需要相同的功能. 如何从DB2调用它? 两个数据库都在Azure SQL服务器中

I need to call function from another database to a database within the Azure sql. That is , there is a function in DB1. I need that same function in DB2. How to call it from DB2? Both database are in azure Sql server

也许您可以看到此文档:

Maybe you can see this documentation:Reporting across scaled-out cloud databases (preview).

弹性查询还引入了一个存储过程,该存储过程提供对分片的直接访问.该存储过程称为sp_execute _remote,可用于在远程数据库上执行远程存储过程或T-SQL代码.它具有以下参数:

Elastic query also introduces a stored procedure that provides direct access to the shards. The stored procedure is called sp_execute _remote and can be used to execute remote stored procedures or T-SQL code on the remote databases. It takes the following parameters:

  1. 数据源名称(nvarchar):RDBMS类型的外部数据源的名称.
  2. 查询(nvarchar):要在每个分片上执行的T-SQL查询.
  3. 参数声明(nvarchar)-可选:具有Query参数中使用的4.参数的数据类型定义的字符串(如sp_executesql).
  4. 参数值列表-可选:以逗号分隔的参数值列表(如sp_executesql).

sp_execute_remote使用调用参数中提供的外部数据源在远程数据库上执行给定的T-SQL语句.它使用外部数据源的凭据连接到shardmap Manager数据库和远程数据库.

The sp_execute_remote uses the external data source provided in the invocation parameters to execute the given T-SQL statement on the remote databases. It uses the credential of the external data source to connect to the shardmap manager database and the remote databases.

示例:

 EXEC sp_execute_remote
        N'MyExtSrc',
        N'select count(w_id) as foo from warehouse'

这意味着您可以在一个数据库中调用一个数据库的函数和存储过程.只需修改SQL语句即可.

It means that you can call the Functions and Stored Procedures of One database In another database, just need to modify the SQL statement.

希望这会有所帮助.