问题
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
回答1:
Maybe you can see this documentation:Reporting across scaled-out cloud databases (preview).
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:
- Data source name (nvarchar): The name of the external data source of type RDBMS.
- Query (nvarchar): The T-SQL query to be executed on each shard.
- Parameter declaration (nvarchar) - optional: String with data type definitions for the 4. parameters used in the Query parameter (like sp_executesql).
- Parameter value list - optional: Comma-separated list of parameter values (like sp_executesql).
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.
Example:
EXEC sp_execute_remote
N'MyExtSrc',
N'select count(w_id) as foo from warehouse'
It means that you can call the Functions and Stored Procedures of One database In another database, just need to modify the SQL statement.
Hope this helps.
来源:https://stackoverflow.com/questions/55411917/is-it-possible-to-call-functions-and-stored-procedures-of-one-database-in-anothe