Cross-Database Query on Azure SQL Database - sql

I am using Azure SQL Database and I have two databases. I want to select one table data on the first database and merge into another (conditional) table of second database.
Is there any SQL solution to solve my problem?

Related

how to reduce the performance issue of two hetrogeneous databases connected via database link

I have connected Oracle database with an Azure SQL Server database via a database link.
I am trying to fetch the data of Azure SQL Server database in Oracle and it is working fine.
But when I am joining one Oracle table and one Azure SQL Server table it is taking too much time to fetch the records.
For example:.
I have one table temp_one in Oracle database and one table temp_two in Azure SQL Server database having dblink like temp.sql.hl.com.
I joined them.
SELECT "EmpAddress",EMPLOYEE_ID
FROM temp_one a
INNER join temp_two#temp.sql.hk.com b
on a.EMPLOYEE_ID = b."EmpID";
Even this normal join is taking 8 seconds.
Note: I am trying to fetch the data in Oracle.
Please help me to resolve it.

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.

Query for multiple databases

Is there a way to write a single query so that if you are connected to database A it does one thing and if you are connected to database B it does another?
I am using SSMS 2008 to access SQL 2000 servers.
You can define views on database A and on database B with the same name and columns, but different construction. Then your query is just to select from the view.

How can I select data in the same query from two different servers and databases from SQL Server Management Studio?

How can I select data in the same query from two different databases that are on two different servers, one DB2 Server and the other a SQL Server?
On your sql server, set up a linked server to the db2 database.
Then write your query on sql server. I suggest that you use openquery for the db2 stuff. If you have to combine the data, populate a sql server temp table with the openquery results and work from there.
The reason I suggest this is performance. I have found that if you use this syntax
select somefields
from server.database.owner.table
where whatever
sql server will bring back the entire table from the linked server and apply the where clause afterwards.
You can set up a linked server http://support.microsoft.com/kb/222937
How to create a linked server

Periodically store data from a PostgreSQL table to SQL Server 2005 table (with the same schema)

I have a PostgreSQL database that stores real-time data from sensors in a specific table (every 30sec).
What I want to do, is to get periodically the data from the remote PostgreSQL database (for instance every 30sec) and store them in SQL Server 2005 to manipulate them locally. I don't care about having the two databases with duplicate tables. Actually this is what I want to achieve!
So far, I have as Linked Server the PostgreSQL to SQL Server and I can query and retrieve the sensor data. However, I prefer to store them in my SQL Server for performance reasons.
Solution so far:
Make select openquery statements with the linked PostgreSQL and insert the results to my table in SQL Server. Repeat this periodically and store fresh data only (e.g. with a larger timestamp).
I assume that my proposed solution is not ideal. I want to know what are the best practices to achieve this synchronization between the two databases.
Thank you in advance!
If you don't want to write your own code(implementations) to do that you can use SymmetricDS to synch the table from postgreSQL to MSSQL .