🔒 Guided

Pre-launch preview. Authorised access only.

Incorrect code

Guided by A Guide to Cloud
Explore AB-900 AI-901
Guided DP-800 Domain 1
Domain 1 — Module 5 of 10 50%
5 of 28 overall

DP-800 Study Guide

Domain 1: Design and Develop Database Solutions

  • Table Design: Columns, Types, and Indexes Free
  • Constraints: Protecting Your Data Free
  • Specialised Tables and Graph Queries Free
  • JSON in SQL: Store, Query, and Index
  • Programmability: Views, Functions, Procedures, and Triggers
  • Advanced T-SQL: CTEs, Windows, and Correlated Queries
  • Pattern Power: Regular Expressions in T-SQL
  • Fuzzy String Matching: Finding Similar Text
  • AI-Assisted SQL with GitHub Copilot Free
  • MCP: Connecting AI to Your Database

Domain 2: Secure, Optimize, and Deploy Database Solutions

  • Encryption: Always Encrypted and Column-Level
  • Dynamic Data Masking and Row-Level Security
  • Permissions, Auditing, and Passwordless Access
  • Transaction Isolation and Concurrency
  • Query Performance: Plans, DMVs, and Query Store
  • SQL Database Projects: Build and Validate
  • CI/CD Pipelines for SQL Databases
  • Data API Builder: REST and GraphQL from SQL
  • Securing AI and API Endpoints
  • Change Detection: CES, CDC, and Change Tracking
  • Azure Integration and Monitoring

Domain 3: Implement AI Capabilities in Database Solutions

  • External AI Models: Choose, Create, Manage
  • Embeddings: Design, Chunk, and Generate
  • Choose Your Search Strategy
  • Vector Data: Types, Indexes, and Storage
  • Vector Search: Distance, ANN, and ENN
  • Hybrid Search and Reciprocal Rank Fusion
  • RAG with SQL: Prompt, Process, Respond

DP-800 Study Guide

Domain 1: Design and Develop Database Solutions

  • Table Design: Columns, Types, and Indexes Free
  • Constraints: Protecting Your Data Free
  • Specialised Tables and Graph Queries Free
  • JSON in SQL: Store, Query, and Index
  • Programmability: Views, Functions, Procedures, and Triggers
  • Advanced T-SQL: CTEs, Windows, and Correlated Queries
  • Pattern Power: Regular Expressions in T-SQL
  • Fuzzy String Matching: Finding Similar Text
  • AI-Assisted SQL with GitHub Copilot Free
  • MCP: Connecting AI to Your Database

Domain 2: Secure, Optimize, and Deploy Database Solutions

  • Encryption: Always Encrypted and Column-Level
  • Dynamic Data Masking and Row-Level Security
  • Permissions, Auditing, and Passwordless Access
  • Transaction Isolation and Concurrency
  • Query Performance: Plans, DMVs, and Query Store
  • SQL Database Projects: Build and Validate
  • CI/CD Pipelines for SQL Databases
  • Data API Builder: REST and GraphQL from SQL
  • Securing AI and API Endpoints
  • Change Detection: CES, CDC, and Change Tracking
  • Azure Integration and Monitoring

Domain 3: Implement AI Capabilities in Database Solutions

  • External AI Models: Choose, Create, Manage
  • Embeddings: Design, Chunk, and Generate
  • Choose Your Search Strategy
  • Vector Data: Types, Indexes, and Storage
  • Vector Search: Distance, ANN, and ENN
  • Hybrid Search and Reciprocal Rank Fusion
  • RAG with SQL: Prompt, Process, Respond
Domain 1: Design and Develop Database Solutions Premium ⏱ ~14 min read

Programmability: Views, Functions, Procedures, and Triggers

Encapsulate logic in reusable database objects — views for simplified queries, functions for calculations, stored procedures for operations, and triggers for automatic reactions.

Reusable logic in the database

☕ Simple explanation

Think of a kitchen with recipes, gadgets, and automatic timers.

A view is like a recipe card — it saves a complex query so you do not have to remember it every time. A function is like a kitchen gadget — give it ingredients (inputs) and it gives back a result (a calculated value or a mini-table). A stored procedure is like a full cooking instruction — it can do multiple things: fetch data, insert rows, update records, all in one call. A trigger is like an automatic timer — it fires by itself when something happens (a row is inserted, updated, or deleted).

Each tool has its place. The exam tests whether you know which one fits each scenario.

Programmability objects encapsulate logic at the database layer. The DP-800 exam covers five types: views (virtual tables), scalar functions (return a single value), table-valued functions (return a result set), stored procedures (execute operations), and triggers (fire automatically on DML or DDL events).

Key design decisions include: views vs inline TVFs for query abstraction, scalar functions vs computed columns for calculations, stored procedures vs functions for data modification, and when triggers are appropriate vs when they should be replaced with application logic or Change Data Capture.

Views: saved queries

A view is a named SELECT statement. It does not store data — it runs the query every time you reference it.

CREATE VIEW vw_ActiveCustomers AS
SELECT c.CustomerId, c.FullName, c.Email, COUNT(o.OrderId) AS OrderCount
FROM Customers c
INNER JOIN Orders o ON c.CustomerId = o.CustomerId
WHERE c.Status = 'Active'
GROUP BY c.CustomerId, c.FullName, c.Email;

-- Use it like a table
SELECT * FROM vw_ActiveCustomers WHERE OrderCount > 10;

Indexed views (materialised views)

For expensive views queried frequently, you can materialise the results with a unique clustered index:

CREATE VIEW vw_ProductSales WITH SCHEMABINDING AS
SELECT p.ProductId, p.Name, SUM(oi.Quantity) AS TotalSold, COUNT_BIG(*) AS RowCount
FROM dbo.Products p
INNER JOIN dbo.OrderItems oi ON p.ProductId = oi.ProductId
GROUP BY p.ProductId, p.Name;
GO

CREATE UNIQUE CLUSTERED INDEX IX_vw_ProductSales
ON vw_ProductSales (ProductId);

Requirements for indexed views: SCHEMABINDING, deterministic functions only, COUNT_BIG(*) for aggregations, no subqueries, outer joins, or UNION.

Scalar functions: one value out

A scalar function takes parameters and returns a single value.

CREATE FUNCTION dbo.fn_CalculateDiscount(
    @Price DECIMAL(10,2),
    @Tier NVARCHAR(20)
)
RETURNS DECIMAL(10,2)
AS
BEGIN
    RETURN CASE @Tier
        WHEN 'Gold' THEN @Price * 0.20
        WHEN 'Silver' THEN @Price * 0.10
        WHEN 'Bronze' THEN @Price * 0.05
        ELSE 0
    END;
END;

-- Use in a query
SELECT Name, Price, dbo.fn_CalculateDiscount(Price, CustomerTier) AS Discount
FROM Products;
💡 Exam tip: Scalar function performance trap

Traditional T-SQL scalar functions are called row by row — they cannot be parallelised. For a table with 10 million rows, a scalar function in the SELECT list runs 10 million times sequentially.

Mitigation strategies:

  • Use inline table-valued functions instead (the optimiser can expand them)
  • Use computed columns for simple calculations
  • In SQL Server 2019+, scalar UDF inlining can automatically convert eligible scalar functions into inline expressions

The exam may present a slow query that uses a scalar function — the fix is often replacing it with an inline TVF or computed column.

Table-valued functions: a table out

Table-valued functions return a result set. There are two types:

Inline TVF (preferred)

-- Inline TVF: single SELECT statement, optimiser can expand it
CREATE FUNCTION dbo.fn_GetCustomerOrders(@CustomerId INT)
RETURNS TABLE
AS
RETURN (
    SELECT OrderId, OrderDate, TotalAmount
    FROM Orders
    WHERE CustomerId = @CustomerId
);

-- Use with CROSS APPLY
SELECT c.FullName, o.OrderDate, o.TotalAmount
FROM Customers c
CROSS APPLY dbo.fn_GetCustomerOrders(c.CustomerId) o;

Multi-statement TVF

-- Multi-statement TVF: declares a table variable, populates it with logic
CREATE FUNCTION dbo.fn_GetOrderSummary(@StartDate DATE, @EndDate DATE)
RETURNS @Summary TABLE (
    ProductId INT,
    ProductName NVARCHAR(200),
    TotalQuantity INT,
    TotalRevenue DECIMAL(12,2)
)
AS
BEGIN
    INSERT INTO @Summary
    SELECT p.ProductId, p.Name, SUM(oi.Quantity), SUM(oi.Quantity * oi.UnitPrice)
    FROM Products p
    INNER JOIN OrderItems oi ON p.ProductId = oi.ProductId
    INNER JOIN Orders o ON oi.OrderId = o.OrderId
    WHERE o.OrderDate BETWEEN @StartDate AND @EndDate
    GROUP BY p.ProductId, p.Name;
    RETURN;
END;
Function types — the exam favours inline TVFs for performance
FeatureInline TVFMulti-Statement TVFScalar Function
ReturnsTable (single SELECT)Table (populated with logic)Single value
PerformanceBest — optimiser inlines itSlower — treated as a black boxSlowest — row-by-row execution
Can modify data?NoNoNo
ParallelismYesLimitedNo (unless inlined)
Use whenParameterised views, reusable queriesComplex multi-step logic returning rowsSimple calculations on single values

Stored procedures: full operations

Stored procedures can do everything: SELECT, INSERT, UPDATE, DELETE, call other procedures, use transactions, and return multiple result sets.

CREATE PROCEDURE dbo.usp_ProcessOrder
    @CustomerId INT,
    @ProductId INT,
    @Quantity INT
AS
BEGIN
    SET NOCOUNT ON;
    BEGIN TRY
        BEGIN TRANSACTION;

        -- Check stock
        DECLARE @Stock INT;
        SELECT @Stock = StockLevel FROM Products WHERE ProductId = @ProductId;

        IF @Stock < @Quantity
            THROW 50001, 'Insufficient stock.', 1;

        -- Create order
        INSERT INTO Orders (CustomerId, OrderDate, Status)
        VALUES (@CustomerId, GETUTCDATE(), 'Pending');

        DECLARE @OrderId INT = SCOPE_IDENTITY();

        -- Add line item and reduce stock
        INSERT INTO OrderItems (OrderId, ProductId, Quantity)
        VALUES (@OrderId, @ProductId, @Quantity);

        UPDATE Products SET StockLevel = StockLevel - @Quantity
        WHERE ProductId = @ProductId;

        COMMIT TRANSACTION;
        SELECT @OrderId AS NewOrderId;
    END TRY
    BEGIN CATCH
        IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
        THROW;
    END CATCH;
END;

Triggers: automatic reactions

Triggers fire automatically when a DML event (INSERT, UPDATE, DELETE) occurs. They use the special INSERTED and DELETED virtual tables.

CREATE TRIGGER trg_AuditPriceChange
ON Products
AFTER UPDATE
AS
BEGIN
    SET NOCOUNT ON;
    IF UPDATE(Price)
    BEGIN
        INSERT INTO PriceAuditLog (ProductId, OldPrice, NewPrice, ChangedAt, ChangedBy)
        SELECT d.ProductId, d.Price, i.Price, GETUTCDATE(), SYSTEM_USER
        FROM INSERTED i
        INNER JOIN DELETED d ON i.ProductId = d.ProductId
        WHERE i.Price <> d.Price;
    END;
END;
💡 Exam tip: When NOT to use triggers

Triggers are powerful but dangerous:

  • They run inside the same transaction (a slow trigger slows every INSERT/UPDATE)
  • They can fire other triggers (cascading trigger chains)
  • They are invisible to application developers (hard to debug)
  • They cannot be easily unit tested

Better alternatives:

  • Temporal tables replace audit triggers
  • Change Data Capture (CDC) or Change Event Streaming (CES) replace data sync triggers
  • Stored procedures with explicit logic replace business rule triggers

Use triggers only when you need guaranteed, engine-level enforcement that cannot be bypassed.

Question

What is the performance difference between inline TVFs and multi-statement TVFs?

Click or press Enter to reveal answer

Answer

Inline TVFs are a single SELECT statement that the query optimiser can expand and optimise like a subquery. Multi-statement TVFs are treated as black boxes — the optimiser cannot see inside them, leading to poor cardinality estimates and slower execution.

Click to flip back

Question

What are the INSERTED and DELETED virtual tables in a trigger?

Click or press Enter to reveal answer

Answer

INSERTED contains the new row values (for INSERT and UPDATE triggers). DELETED contains the old row values (for UPDATE and DELETE triggers). For an UPDATE, INSERTED has the new values and DELETED has the old values — comparing them lets you detect which columns changed.

Click to flip back

Question

What is SCHEMABINDING on a view?

Click or press Enter to reveal answer

Answer

SCHEMABINDING prevents the underlying tables from being altered or dropped while the view exists. It is required for indexed (materialised) views and ensures the view definition stays valid.

Click to flip back

Knowledge Check

Ingrid at Nordic Shield Insurance has a query that calculates the risk score for each policy using a complex formula involving 6 columns. The query runs on 5 million rows and is unacceptably slow because the risk calculation is in a scalar function. What should Ingrid do?

Knowledge Check

Dev at PixelForge Studios needs to automatically log every deletion from the Projects table, capturing who deleted the record and when. The log must be guaranteed — no application can skip it. Which approach is most appropriate?

🎬 Video coming soon

Next up: Advanced T-SQL: CTEs, Windows, and Correlated Queries — write powerful queries with common table expressions, window functions, and correlated subqueries.

← Previous

JSON in SQL: Store, Query, and Index

Next →

Advanced T-SQL: CTEs, Windows, and Correlated Queries

Guided

I learn, I simplify, I share.

A Guide to Cloud YouTube Feedback

© 2026 Sutheesh. All rights reserved.

Guided is an independent study resource and is not affiliated with, endorsed by, or officially connected to Microsoft. Microsoft, Azure, and related trademarks are property of Microsoft Corporation. Always verify information against Microsoft Learn.