Forum Discussion

apturlov's avatar
apturlov
Super User
1 year ago
Solved

Querying a Fabric SQL Database from a Notebook

Fabric SQL Database is a relatively new storage option in Microsoft Fabric, ideal for transactional workloads. However, for data science, machine learning, or exploratory analytics, connecting via SQL endpoints can be limiting. These workloads benefit from the flexibility of Fabric Notebooks, but SQL Databases aren't natively accessible from notebooks.

You can work around the notebook access limitation by creating a Lakehouse shortcut to a Fabric SQL Database. This exposes the SQL tables as Delta-like folders in the Lakehouse’s Files section, making them accessible from notebooks.

So, here is a SQL database in Fabric populated with a samle dataset:

Next, I created a shortcut in a Lakehouse in the same workspace:

A shortcut appears under the Files section in the Lakehouse with a hierarchical folder structure Schema/Table. The file content of a table folder reveals that this is a delta table. Now I can create a Notebook in this Lakehouse and use a simple code to load the SQL table content into a dataframe as a delta format:

I can go one step further and create a temporary view from the dataframe for convenience:


This approach can be useful for exploratory data analysis in notebooks, lightweight transformations before writing to a Lakehouse table, or bridging SQL and Spark workflows without duplicating data.
However, keep in mind, that a SQL database shortcut is read-only, not changes can be made to the underlying Fabric SQL database from a notebook via a shortcut.

4 Replies