简体   繁体   中英

Best way to update one SQL Server with data from another SQL Server?

I would like to run a job that automatically snapshots a DB1 (a stored procedure) and merges the result with a table in DB2. Basically I would like to query DB1 from DB2.

What is the best way to do this? They are run on two different SQL Servers in two different resource groups in Azure.

At the moment it won't let me created a linked server - tells me the sp does not exist when I try create it.

You have two databases run on two different SQL Servers in two different resource groups in Azure.

Basically you would like to query DB1 from DB2.

For Azure SQL database, you want to query across different database, you can use Azure SQL Database elastic query .

Summary:

The elastic query feature (in preview) enables you to run a Transact-SQL query that spans multiple databases in Azure SQL Database. It allows you to perform cross-database queries to access remote tables, and to connect Microsoft and third-party tools (Excel, Power BI, Tableau, etc.) to query across data tiers with multiple databases. Using this feature, you can scale out queries to large data tiers in SQL Database and visualize the results in business intelligence (BI) reports.

You can using the bellow code to query from the remote database:

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

For more details, please see: Stored procedure for remote T-SQL execution: sp_execute_remote .

You can also reference this blog: Is it Possible to call Functions and Stored Procedures of One database In another database- Azure Sql server .

With elastic query, you can call the stored procedure in DB1, merges the result with a table in DB2

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM