How to create a Foreign Table in a Lakehouse on Microsoft Fabric
This tutorial shows how to create a Foreign Table in the Lakehouse of Microsoft Fabric to query external data (for example, a Parquet file or an external table). The Foreign Table lets you extend the Lakehouse with external sources without copying data, useful for integrating systems and reducing duplication.
Prerequisites
- Account with access to Microsoft Fabric and permissions to edit a Lakehouse.
- An existing Lakehouse in OneLake or permission to create a new one.
- Accessible external source (e.g., Parquet file in OneLake or external endpoint with credentials).
- Basic T-SQL knowledge to run commands in the Notebook or Warehouse.
Step 1: Prepare the external source and get the path
Identify the external source you want to use. If it is a Parquet file in OneLake, copy the relative path in the Lakehouse. If it is an external endpoint, confirm the URL and credentials. The Foreign Table creates a logical pointer to that location.
Step 2: Open a Notebook or Warehouse to run T-SQL
Choose where you will run the commands: a Notebook with T-SQL language or a Warehouse (T-SQL). Open the resource and connect it to the Lakehouse where you will create the Foreign Table. Using a T-SQL session allows you to create objects and run immediate queries.
Step 3: Create an external data source (optional as needed)
Some sources require first defining an external data source with credentials or access settings. For OneLake/simple paths, this may not be necessary. Example of creating a data source for a supported endpoint:
CREATE EXTERNAL DATA SOURCE MyExternalSource
WITH (
LOCATION = 'abfss://@.dfs.core.windows.net/folder/',
CREDENTIAL = MyCredential
);
Replace MyCredential with a credential previously created in the environment, if required.
Step 4: Create the Foreign Table with T-SQL
Use CREATE EXTERNAL TABLE or CREATE FOREIGN TABLE according to Fabric support to map the source structure. Here is a generic example that points to a Parquet file in a Lakehouse path.
CREATE EXTERNAL TABLE dbo.ForeignSales (
SaleID bigint,
SaleDate datetime2,
Amount decimal(18,2)
)
WITH (
LOCATION = '/lakehouse/path/to/folder/sales.parquet',
DATA_SOURCE = MyExternalSource,
FILE_FORMAT = 'Parquet'
);
If your source is a folder with multiple Parquet files, the LOCATION can point to the folder. If you did not use DATA_SOURCE, specify only the absolute LOCATION in OneLake.
Step 5: Define compatible schemas and types
Confirm that the T-SQL types you defined match the actual data. Common errors: incompatible types (e.g., datetime vs string) or null fields without allowing NULL. Adjust the table definition as needed.
Step 6: Test queries and performance
After the Foreign Table is created, run queries to validate. Avoid SELECT * on large volumes; filter and limit to test. If necessary, create views or materializations in the Lakehouse to improve performance.
-- Simple test
SELECT TOP 10 SaleID, SaleDate, Amount
FROM dbo.ForeignSales
ORDER BY SaleDate DESC;
-- Count to validate volume
SELECT COUNT(*) AS TotalRows FROM dbo.ForeignSales;
Verify the result
Confirm that queries return the expected data and that observed types make sense. Check the existence of the object with a catalog lookup and inspect metadata. Common errors include incorrect paths, permissions and file formats. If there are no results, validate the LOCATION and the data source permissions.
Conclusion
Creating a Foreign Table in the Lakehouse of Microsoft Fabric allows you to query external data without duplicating files, facilitating integration and saving space. Next steps: create views that join external data with internal tables, or materialize results to optimize performance. Tip: when testing, always start with LIMIT/TOP to avoid cost and performance surprises — which source do you want to connect next?