How can I join tables from different databases in Azure SQL (SAAS)? - sql

Having the older application that joins SQL tables from different databases like this:
SELECT a.value, b.value
FROM databaseA.dbo.tableA AS a
JOIN databaseB.dbo.tableB AS b
ON a.thekey == b.thekey
Being 3rd party, we have to accept the decision of the main implementor for the customer to use the license Azure SQL SAAS (Software As A Service; I am new to that, sorry if some terms are incorrect).
Is it possible to have databaseA and databaseB (that part is possible, checked through SSMS) in the Azure SQL and do the same JOIN (that part is unknown to me)?
I tried, but it failed. I do not know if something more have to be done to make the other database visible from each of the databases, or if it is not possible at all.
If it is not possible, what is the recommended technique to replace the old SQL code?

As you comment said: "I understand that it is different than working within one physical SQL Server. On the other hand, the different servers is probably related to possible replication. Is that correct? ", yes, you're right.
For Azure SQL database(PSSA), we only can use the elastic query to achieve the cross database query:
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.
Note:
Make sure the primary database have the permission to access the remote databases. Add the the client IP to their database firewall. The remote database can be in different Azure SQL Server.
If you are using Azure SQL managed instance and Azure SQL Server on Azure VM, you can run this across query like on-premise SQL Server.

Related

Identify relationships between multiple databases in SQL

I am working on migrating an application from one server to the other. According to the connection string of this application, it is touching different databases. Meaning a view query in DB1 will touch a table in DB2. So while migrating this application, I constant get to see chain of 'Database unavailable' errors and every time I see such error, I have to migrate that specific database.
I am wondering, since we have ER diagrams to know about relationships between tables in a database, is there any way in SQL server to know the relationships/linkages between different DATABASES in a server? Are there any tool that does this?
Depending on number of databases you have, here would be a somehow quick way you can find that out (number of required search = number of available databases in the server):
Use 'SQL Search' application of Red-get
(https://www.red-gate.com/dynamic/products/sql-development/sql-search/download)
and search for the other database names one after another by selecting
your database of interest. Select all objects.
If you have metadata oriented design (a Stored Procedure looping through the names of different other Stored Procedures / Functions from different databases which are stored in a table as metadata and executing them with a wrapper Stored Procesure), then you will have make use of SQL Locator software (http://www.sqllocator.com/Downloads.html) to search for database names in SQL Table values.
Both of the above software are free.
You need to have SSMS (SQL Server Management Studio) installed to be able to use this application. After installation, ‘SQL Search’ will be directly available in your SSMS as an add-on.
SQL Locator can be directly used by providing the SQL Server name and your SQL Server credential.
Note:- The above steps will help you find out the referenced databases from a certain database within the same SQL Server. If you need to find out databases from Linked Server (I do not believe your question is asking that anyways), then you will have to smartly utilize the same above tools to find the external server reference by searching the external server name.

Query from DB Azure to Local Database

I have this situation.
I have 2 BD , one DB in Azure with Name: TEST1 and another in my computer with name Test2.
I want to execute querys in BD Test1 to consult information in DB Test2.
How can i do this?
Regards.
Thanks!
SQL Azure does not support linked servers. (SQL Azure Managed Instance does for SQL-SQL connections, FWIW).
Absent that, your options are:
* run SQL Server on your local machine and run the query from there to join (using a linked server to talk to SQL Azure's db)
* run SQL Server in a VM in azure to do linked servers there against your two databases.
SQL Server 2019 CTPs do contain an external table feature that is able to talk to ODBC sources like SQL Server/SQL Azure, but that's not materially any different than the two options I suggested for you here. (It's a bit more involved to do this path and it's not supported for production workloads at this time since it's pre-RTM).

I am a newbie to DMBS system is it possible to join two Database Systems like SQL and Netezza?

Is it possible to join two tables from different database systems such as SQL and Netezza using any query language.
Specifically is it possible to achieve a join in AQT.
Is it possible for a tool like AQT ( Advanced Querying Tool) to provide a platform which allows us to connect the tables from these different database systems
You can try creating linked server in SQL. But doing so have an overhead on the SQL server from DBA point of view. You need extra privileges to create a linked server.

Querying multiple database systems

Is it possible to query (or better, join) data from two different database systems? Let's say I have postgresql and SQL Server and I want to join a table from postgres to a table in SQL Server?
It doesn't matter which programming language.
What about utilizing a linked server? I use one to query an AS400 and join the results back to Microsoft SQL Server.
Quote from Microsoft documentation:
Configure a linked server to enable the SQL Server Database Engine to
execute commands against OLE DB data sources outside of the instance
of SQL Server. Typically linked servers are configured to enable the
Database Engine to execute a Transact-SQL statement that includes
tables in another instance of SQL Server, or another database product
such as Oracle. Many types OLE DB data sources can be configured as
linked servers, including Microsoft Access and Excel. Linked servers
offer the following advantages:
The ability to access data from outside of SQL Server.
The ability to issue distributed queries, updates, commands, and transactions on heterogeneous data sources across the enterprise.
The ability to address diverse data sources similarly.

Can I connect two external databases using Microsoft Access?

First, I apologize if this has been asked or is a trivial question.
But, is it possible to connect to two external SQL databases through Microsoft Access?
By way of background one is our CRM and one is our email management system. The two are completely distinct databases. And, reside in different physical and virtual servers.
Our objective is to be able to gain insight into our email marketing efforts as it relates to client activities captured in our CRM.
We currently use an ODBC connection to read data from our CRM database.
Really, we need more information, but basically yes it is possible. All you need to do is link to the tables in the SQL databases, then run the query on the linked tables with a JOIN.
This page will tell you how to link to an SQL table: http://office.microsoft.com/en-au/access-help/import-or-link-to-sql-server-data-HA010200494.aspx
It is possible to do this in MS Access (as already said in Makita's answer).
But you won't get the maximum performance this way, because there's a certain overhead caused by MS Access on your machine (which is relatively slow compared to the DB servers and probably has a slower network connection than the DB servers), pulling data from two different DB servers over the network.
Since you tagged your question with sql-server, there's another possible solution using a feature of SQL Server: linked servers.
You can create a linked server in SQL Server A, that links to SQL Server B.
(see the above link for more information about how to do this)
Then, you can query tables on SQL Server B from SQL Server A (and even join tables from both servers) with the following syntax:
-- execute this on Server A
use DatabaseA
select *
from TableA a
inner join ServerB.DatabaseB.dbo.TableB b on a.ID = b.ID
(this code assumes that TableA is a table in DatabaseA, which is on ServerA, and so on)
This will be way faster than linking the tables in MS Access (the more data you need to pull, the faster it will be) because you're using the superior CPU power and network connection of the database servers.