Database track

SQL Server Tutorial

Query and design relational databases with T-SQL: joins, CTEs, window functions, procedures, indexes.

BeginnerExamples run on SQL Server 2022 and Azure SQL Database.
0/31 complete
Topics
31
Full lessons
31
Est. hours
~6
Interview Qs
28

Overview

Microsoft SQL Server is a relational database management system. You query it with T-SQL, Microsoft’s dialect of SQL.

The track moves from SELECT basics to joins, window functions, stored procedures, transactions, indexing and query tuning.

What you will learn

  • Write SELECT queries with filtering, sorting and grouping
  • Combine tables with joins, subqueries and CTEs
  • Encapsulate logic in views, functions and stored procedures
  • Design normalised schemas and tune queries with indexes

Prerequisites

None — this track starts from the very beginning.

Learning path

The recommended sequence, from beginner to advanced. Each stage builds on the one before.

  1. 1Fundamentals · 4 topics · Beginner
    Database Fundamentals · SQL Server Installation · Database and Table Creation · Data Types
  2. 2Querying · 5 topics · Beginner
    SELECT · WHERE · ORDER BY · GROUP BY · HAVING
  3. 3Modifying Data · 3 topics · Beginner
    INSERT · UPDATE · DELETE
  4. 4Combining Data · 5 topics · Beginner → Intermediate
    Joins · Subqueries · Common Table Expressions · Window Functions · Aggregate Functions
  5. 5Programmability · 5 topics · Intermediate
    Views · Stored Procedures · User-Defined Functions · Triggers · Transactions
  6. 6Performance & Design · 7 topics · Intermediate → Advanced
    Indexes · Execution Plans · Query Optimization · Constraints · Primary and Foreign Keys · Normalization · SQL Security
  7. 7Practice · 2 topics · Advanced
    Practical Exercises · Interview Questions

Complete topic list

31 topics
1

Fundamentals

4 topics
  1. Database FundamentalsBeginner5m
  2. SQL Server InstallationBeginner5m
  3. Database and Table CreationBeginner5m
  4. Data TypesBeginner5m
2

Querying

5 topics
  1. SELECTBeginner5m
  2. WHEREBeginner5m
  3. ORDER BYBeginner5m
  4. GROUP BYBeginner5m
  5. HAVINGBeginner5m
3

Modifying Data

3 topics
  1. INSERTBeginner5m
  2. UPDATEBeginner5m
  3. DELETEBeginner5m
4

Combining Data

5 topics
  1. JoinsBeginner5m
  2. SubqueriesBeginner5m
  3. Common Table ExpressionsIntermediate5m
  4. Window FunctionsIntermediate5m
  5. Aggregate FunctionsIntermediate5m
5

Programmability

5 topics
  1. ViewsIntermediate5m
  2. Stored ProceduresIntermediate5m
  3. User-Defined FunctionsIntermediate5m
  4. TriggersIntermediate5m
  5. TransactionsIntermediate5m
6

Performance & Design

7 topics
  1. IndexesIntermediate5m
  2. Execution PlansIntermediate5m
  3. Query OptimizationAdvanced5m
  4. ConstraintsAdvanced5m
  5. Primary and Foreign KeysAdvanced5m
  6. NormalizationAdvanced5m
  7. SQL SecurityAdvanced5m
7

Practice

2 topics
  1. Practical ExercisesAdvanced5m
  2. Interview QuestionsAdvanced15m

Visual guides

1 diagram

Code example

A taste of the track, from Database Fundamentals.

SQLAsking a database a question Illustrative
-- Which customers live in Pune?
SELECT CustomerId, Name, City
FROM Customers
WHERE City = 'Pune';
Expected output
CustomerId  Name   City
1           Asha   Pune
3           Meera  Pune

Practice exercises

Show all 30 exercises
ORDER BY

List products from cheapest to most expensive, breaking ties by name.

GROUP BY

Count how many orders each status has.

HAVING

List categories whose total product value is under 20,000.

INSERT

Insert a customer named Zoya from Jaipur and return the new CustomerId.

UPDATE

Mark order 103 as Delivered and show its old and new status.

DELETE

Write a soft delete: add an IsDeleted BIT column to Products and “delete” the Pen.

Joins

List students who are NOT enrolled in any course.

Subqueries

List products that have been ordered at least once, using IN.

Common Table Expressions

Use a CTE to find each customer’s number of orders, then return only customers with more than one order.

Window Functions

Return only the most expensive product in each category.

Aggregate Functions

Return the total quantity of items sold across all orders.

Views

Create a view vActiveProducts showing only Name and Price, then query it.

Stored Procedures

Call dbo.EnrollStudent from C# with ADO.NET and read the output parameter.

User-Defined Functions

Write an inline TVF dbo.fn_OrdersByStatus(@status) returning OrderId and OrderDate.

Triggers

Explain what inserted and deleted contain during a DELETE statement.

Transactions

What would the balances be if XACT_ABORT were OFF and there were no TRY…CATCH, and the second UPDATE failed?

Indexes

Design an index for: SELECT Name, Price FROM Products WHERE Category = @c ORDER BY Price.

Execution Plans

A plan shows an Index Seek followed by 50,000 Key Lookups. What is the usual fix?

Query Optimization

Rewrite WHERE LEFT(Name, 3) = 'Lap' to be SARGable.

Constraints

Add a CHECK constraint to Orders allowing only Pending, Delivered or Cancelled statuses.

Primary and Foreign Keys

Recreate the OrderItems → Orders foreign key with ON DELETE CASCADE and explain the effect.

Normalization

A Students table has columns Course1, Course2, Course3. Which normal form does it break and how would you fix it?

SQL Security

Grant a reporting role read-only access to a reporting schema.

Practical Exercises

Exercise 2: return each customer’s most recent order (customer name, order id, order date).

Common interview questions

Frequently asked questions

Is SQL Server free?
SQL Server Developer and Express editions are free. Developer edition is for development and testing only; Express is free for production with size limits.