Create and Use Views in Fabric Warehouse – SQL Tutorial with Example | Microsoft Fabric Tutorial

Create and Use Views in Fabric Warehouse – SQL Tutorial with Example

Create and Use Views in Fabric Warehouse – SQL Tutorial with Example

In this Microsoft Fabric tutorial, we explore how to use SQL Views in Fabric Warehouse to simplify queries, secure data, and generate reusable logic. Views allow you to abstract complex logic and limit sensitive access while maintaining flexibility in data operations.

🧠 What is a VIEW?

A VIEW is a virtual table based on the result of a SQL query. Views do not store data physically but allow easier querying, especially when dealing with complex joins, filters, or column-level security.

Benefits of Using Views:

  • Simplifies complex queries
  • Provides abstraction and data masking
  • Promotes reusable query logic
  • Improves security by exposing only needed columns

📂 Supported & Unsupported View Types in Fabric

  • ✅ Regular Views (non-materialized)
  • ✅ Views on external tables
  • ❌ Materialized Views – Not supported
  • ❌ Indexed Views – Not supported

🏗️ Step 1: Create a Sample Table

CREATE TABLE dbo.Employees (
    EmployeeID INT,
    FullName VARCHAR(50),
    Department VARCHAR(50),
    Salary DECIMAL(10,2),
    HireDate DATE
);

💾 Step 2: Insert Sample Data

INSERT INTO dbo.Employees VALUES
(1, 'Aamir Shahzad', 'IT', 80000, '2020-01-15'),
(2, 'Sara Khan', 'HR', 65000, '2021-06-10'),
(3, 'John Doe', 'Finance', 90000, '2019-03-20'),
(4, 'Mia Wong', 'IT', 75000, '2022-02-25');

🔍 Step 3: Create a Basic View

View that returns employee names and departments:

CREATE VIEW dbo.vw_EmployeeBasicInfo AS
SELECT FullName, Department
FROM dbo.Employees;

-- Query the view
SELECT * FROM dbo.vw_EmployeeBasicInfo;

🔐 Step 4: Create a Security View

Hide salary details from general users:

CREATE VIEW dbo.vw_PublicEmployeeInfo AS
SELECT EmployeeID, FullName, Department
FROM dbo.Employees;

-- Query the view
SELECT * FROM dbo.vw_PublicEmployeeInfo;

📊 Step 5: Create an Aggregated View

Average salary by department:

CREATE VIEW dbo.vw_DepartmentSalaryAvg AS
SELECT Department, AVG(Salary) AS AvgSalary
FROM dbo.Employees
GROUP BY Department;

-- Query the view
SELECT * FROM dbo.vw_DepartmentSalaryAvg;

🚫 Step 6: Unsupported View Features

  • ❌ ORDER BY in views (unless used with TOP or OFFSET-FETCH)
  • ❌ Nested CTEs
  • ❌ Procedural logic or parameters

🎬 Watch the Full Tutorial

Blog post written with the help of ChatGPT.