Create, Modify & Manage Tables with T-SQL in Fabric Warehouse | Microsoft Fabric Tutorial

Create, Modify & Manage Tables with T-SQL in Fabric Warehouse | Microsoft Fabric Tutorial

Create, Modify & Manage Tables with T-SQL in Fabric Warehouse

This tutorial walks you through essential T-SQL operations in Microsoft Fabric Warehouse. You’ll learn how to create tables, insert data, update schema, drop columns, and even handle schema evolution when direct alterations aren't supported. Ideal for developers and DBAs new to Fabric!

📘 Step 1: Create a New Table

Let’s begin by creating a basic Employee table.

CREATE TABLE dbo.Employee (
    EmployeeID INT,
    FirstName VARCHAR(50),
    LastName VARCHAR(50),
    Department VARCHAR(50)
);

SELECT * FROM dbo.Employee;

✅ Step 2: Insert Sample Data

INSERT INTO dbo.Employee (EmployeeID, FirstName, LastName, Department)
VALUES
(1, 'Aamir', 'Shahzad', 'IT'),
(2, 'Sara', 'Ali', 'HR'),
(3, 'John', 'Doe', 'Finance');

👁️ Step 3: View Data

SELECT * FROM dbo.Employee;

➕ Step 4: Add a New Column

Add a HireDate column to your table:

ALTER TABLE dbo.Employee
ADD HireDate DATE;

📝 Step 5: Update New Column with Values

UPDATE dbo.Employee SET HireDate = '2023-01-01' WHERE Department = 'IT';
UPDATE dbo.Employee SET HireDate = '2023-02-15' WHERE EmployeeID = 2;
UPDATE dbo.Employee SET HireDate = '2023-03-10' WHERE Department = 'Finance';

👁️ View Updated Table

SELECT * FROM dbo.Employee;

🧽 Step 6: Drop an Unused Column

Remove the Department column once it's no longer needed:

ALTER TABLE dbo.Employee
DROP COLUMN Department;

👀 View Table After Dropping Column

SELECT * FROM dbo.Employee;

⚠️ Step 7: Change Data Type (Unsupported Directly)

Direct column type change like increasing VARCHAR(50) to VARCHAR(100) is not currently supported in Fabric Warehouse. Instead, use a workaround.

✅ Workaround: Migrate to New Table

-- Step 1: Create a new table with updated column size
CREATE TABLE dbo.Employee_New (
    EmployeeID INT,
    FirstName VARCHAR(100),
    LastName VARCHAR(50),
    HireDate DATE
);

-- Step 2: Copy data
INSERT INTO dbo.Employee_New (EmployeeID, FirstName, LastName, HireDate)
SELECT EmployeeID, FirstName, LastName, HireDate
FROM dbo.Employee;

-- Step 3: Drop old table
DROP TABLE dbo.Employee;

-- Step 4: Rename new table
EXEC sp_rename 'dbo.Employee_New', 'Employee';

-- Final view
SELECT * FROM dbo.Employee;

🎬 Watch the Full Tutorial

Blog post written with the help of ChatGPT.