Prepare Data · Topic 3 of 7
Views, Functions, Procedures and Enrichment
Create T-SQL views, inline table-valued functions and stored procedures in a Fabric warehouse, and enrich data by adding new columns and tables.
- 5 min
- Views and inline table-valued functions return data; only stored procedures in a warehouse change data.
- The SQL analytics endpoint supports views, functions and procedures, but its tables are read-only.
- Three-part names (
Item.schema.table) query other items in the same workspace.
What it is
Views, functions and stored procedures are T-SQL objects that hold reusable logic. In Fabric you create them in a warehouse or in a lakehouse's SQL analytics endpoint.
Enriching data means adding information that the source does not have: a calculated column, a category, a lookup value from another table, or a whole new table such as a date dimension.
How it works
Which object to use
| Object | Returns | Can change data | Typical use |
|---|---|---|---|
| View | A result set, used like a table | No | Hide joins and columns, present a clean layer to report authors |
| Inline table-valued function | A table, filtered by parameters | No | A view that takes parameters; also the predicate for row-level security |
| Stored procedure | Optional result sets | Yes, in a warehouse | Load, merge and clean data on a schedule, often run by a pipeline |
On a lakehouse's SQL analytics endpoint you can create views, functions and procedures, but none of them can modify the lakehouse tables. Data changes in T-SQL need a warehouse.
A view that also enriches
CREATE VIEW dbo.vSalesEnriched
AS
SELECT
s.OrderID,
s.OrderDate,
s.Quantity * s.UnitPrice AS LineTotal,
CASE WHEN s.Quantity >= 100 THEN 'Bulk' ELSE 'Standard' END AS OrderSize,
c.Region
FROM dbo.Sales AS s
JOIN dbo.Customer AS c
ON c.CustomerID = s.CustomerID;
The view adds a calculated column, a derived category and a region looked up from another table. The data is computed at query time, not stored.
An inline table-valued function
CREATE FUNCTION dbo.fn_SalesByRegion (@Region varchar(50))
RETURNS TABLE
AS
RETURN
SELECT OrderID, OrderDate, LineTotal
FROM dbo.vSalesEnriched
WHERE Region = @Region;
GO
SELECT * FROM dbo.fn_SalesByRegion('West');
A stored procedure that loads a fact table
CREATE PROCEDURE dbo.usp_LoadDailySales
@LoadDate date
AS
BEGIN
DELETE FROM dbo.FactSales WHERE OrderDate = @LoadDate;
INSERT INTO dbo.FactSales (OrderID, OrderDate, CustomerKey, LineTotal)
SELECT s.OrderID, s.OrderDate, c.CustomerKey, s.Quantity * s.UnitPrice
FROM stg.Sales AS s
JOIN dbo.DimCustomer AS c
ON c.CustomerID = s.CustomerID
WHERE s.OrderDate = @LoadDate;
END;
GO
EXEC dbo.usp_LoadDailySales @LoadDate = '2026-10-01';
Deleting the day before inserting it makes the load safe to rerun. A data pipeline can call the procedure with the Stored procedure activity and pass the date as a parameter.
Querying across items
A warehouse can read other warehouses and lakehouse SQL analytics endpoints in the same workspace with three-part names. This is how a procedure loads a warehouse from a lakehouse:
INSERT INTO dbo.DimProduct (ProductID, ProductName, Category)
SELECT ProductID, ProductName, Category
FROM SalesLakehouse.dbo.products;
Enriching in Spark and Power Query
The same enrichment can happen earlier, in a notebook or a Dataflow Gen2. This PySpark code builds a new date table:
from pyspark.sql import functions as F
dates = spark.sql(
"SELECT explode(sequence(to_date('2024-01-01'), to_date('2026-12-31'), interval 1 day)) AS Date"
)
dim_date = (dates
.withColumn("Year", F.year("Date"))
.withColumn("MonthNo", F.month("Date"))
.withColumn("Month", F.date_format("Date", "MMM")))
dim_date.write.format("delta").mode("overwrite").saveAsTable("dim_date")
In Power Query, Add column > Custom column writes M such as:
Table.AddColumn(Source, "Margin", each [Revenue] - [Cost], type number)
Conditional columns and Column from examples add derived values without writing code.
A worked example
Report authors keep rewriting the same sales and customer join, and a nightly job must load yesterday's orders.
- Create the view
vSalesEnrichedso authors query one object with friendly columns. - Create
fn_SalesByRegionfor regional teams that always filter on one region. - Create
usp_LoadDailySalesin the warehouse and schedule a pipeline that calls it each night with yesterday's date.
If the requirement says "accept a parameter and return rows", choose an inline table-valued function. If it says "insert or update data", choose a stored procedure in a warehouse.
How the exam asks about this
- "Expose a simplified, joined dataset without storing another copy." A view.
- "Load and update tables with T-SQL on a schedule." A stored procedure in a warehouse, called from a data pipeline.
- "Add a column that groups orders into size bands." A
CASEexpression in a view or query, or a conditional column in Power Query.
What to remember for the exam
- Views and inline table-valued functions return data; only stored procedures in a warehouse change data.
- The SQL analytics endpoint supports views, functions and procedures, but its tables are read-only.
- Three-part names (
Item.schema.table) query other items in the same workspace. - Pipelines run stored procedures with the Stored procedure activity and can pass parameters.
- Enrich with calculated columns,
CASEcategories, lookups through joins, and new tables such as a date dimension.
A view is computed every time it is queried. For heavy logic that many reports read, or for Direct Lake models (a view cannot be read in Direct Lake mode), store the result as a table instead.
Common mistakes
Putting INSERT logic in a view or function. Views and functions only return data. Use a stored procedure for loads.
Creating a load procedure on the lakehouse SQL analytics endpoint. It cannot write to lakehouse tables. Load with Spark or a dataflow, or move the tables to a warehouse.
Writing the load so it duplicates rows when rerun. Delete or filter the target range first, so a rerun gives the same result.
Check yourself
Which T-SQL object returns rows filtered by a parameter and can be used in a FROM clause?
An inline table-valued function.
Why does a stored procedure that updates lakehouse tables fail on the SQL analytics endpoint?
The SQL analytics endpoint is read-only for lakehouse tables. Writes need Spark, a dataflow or a pipeline, or a warehouse.
How can a warehouse query a lakehouse table in the same workspace?
With a three-part name such as
SalesLakehouse.dbo.products.
Topic 3 of 7 in Prepare Data
Test yourself on Prepare Data
The full Microsoft DP-600 question bank has 648 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by Microsoft. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.