How to Write a cross-database query in Microsoft Fabric

  1. Writing Cross-Database Queries: You can write queries that access data from different databases within the same Microsoft Fabric workspace.
  2. Examples and Methods: There are different ways to do this, and we’ll explore some examples. You can join tables or views from different databases to perform queries within the same workspace.
  3. Adding SQL Analytics Endpoint or Warehouse: You can add a SQL analytics endpoint or warehouse from your active workspace to the object explorer. This makes it easy to reference them when writing SQL queries or creating visual queries. You can refer to tables in added databases using a three-part name.
  1. Example: For instance, if you add a database named ContosoLakehouse, you can reference a table called ContosoSalesTable from that database using its three-part name in your query.
SELECT * 
FROM ContosoLakehouse.dbo.ContosoSalesTable AS Contoso
INNER JOIN Affiliation
ON Affiliation.AffiliationId = Contoso.RecordTypeID;

Using three-part naming to reference the databases/tables, you can join multiple databases.

SELECT * 
FROM ContosoLakehouse.dbo.ContosoSalesTable AS Contoso
INNER JOIN My_lakehouse.dbo.Affiliation
ON My_lakehouse.dbo.Affiliation.AffiliationId = Contoso.RecordTypeID;

Using three-part naming to reference the database and tables, you can insert data from one database to another.

INSERT INTO ContosoWarehouse.dbo.Affiliation
SELECT * 
FROM My_Lakehouse.dbo.Affiliation;

You can drag and drop tables from added databases to Visual query editor to create a cross-database query.

Related Posts

Secure supply chain: SBOM, SLSA, signing, provenance (plain English)

If you ship software today, you don’t just ship your code. You ship: That whole chain is your software supply chain. And attackers love it, because instead…

Read More

CI/CD for Cloud Apps: Build → Scan → Deploy → Rollback (a practical reference pipeline)

CI/CD sounds simple until you’re responsible for a production system and realize: This guide gives you a reference CI/CD pipeline you can adopt for most cloud apps…

Read More

Policy as Code: OPA/Rego basics + how it prevents bad infra

You know that feeling when an incident starts with a sentence like: Most “bad infra” isn’t malicious. It’s normal engineering drift:new hires, rushed PRs, copy-paste manifests, unclear…

Read More

Reusable IaC Module Design: naming, inputs/outputs, versioning (the engineer’s playbook)

Reusable IaC modules are like internal libraries: if the “API” is clean, teams move fast. If it’s messy, everyone forks it, patches it, and you end up…

Read More

GitOps explained: Argo CD vs Flux, patterns, and anti-patterns

GitOps is one of those ideas that sounds like buzzwords… until you run it for 30 days and suddenly you can’t imagine operating Kubernetes without it. Because…

Read More

Terraform vs CloudFormation vs Pulumi: which fits which team (the practical, engineer-first guide)

You’re not really choosing a tool. You’re choosing how your team will think about infrastructure for the next 2–5 years: This guide helps you decide fast, without…

Read More
guest
0 Comments
Oldest
Newest Most Voted
0
Would love your thoughts, please comment.x
()
x