SQL Server Tutorial
Query and design relational databases with T-SQL: joins, CTEs, window functions, procedures, indexes.
- 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.
- 1Fundamentals · 4 topics · BeginnerDatabase Fundamentals · SQL Server Installation · Database and Table Creation · Data Types
- 2Querying · 5 topics · BeginnerSELECT · WHERE · ORDER BY · GROUP BY · HAVING
- 3Modifying Data · 3 topics · BeginnerINSERT · UPDATE · DELETE
- 4Combining Data · 5 topics · Beginner → IntermediateJoins · Subqueries · Common Table Expressions · Window Functions · Aggregate Functions
- 5Programmability · 5 topics · IntermediateViews · Stored Procedures · User-Defined Functions · Triggers · Transactions
- 6Performance & Design · 7 topics · Intermediate → AdvancedIndexes · Execution Plans · Query Optimization · Constraints · Primary and Foreign Keys · Normalization · SQL Security
- 7Practice · 2 topics · AdvancedPractical Exercises · Interview Questions
Complete topic list
31 topicsFundamentals
4 topics- Database FundamentalsBeginner5m
- SQL Server InstallationBeginner5m
- Database and Table CreationBeginner5m
- Data TypesBeginner5m
Querying
5 topicsCombining Data
5 topics- JoinsBeginner5m
- SubqueriesBeginner5m
- Common Table ExpressionsIntermediate5m
- Window FunctionsIntermediate5m
- Aggregate FunctionsIntermediate5m
Programmability
5 topics- ViewsIntermediate5m
- Stored ProceduresIntermediate5m
- User-Defined FunctionsIntermediate5m
- TriggersIntermediate5m
- TransactionsIntermediate5m
Performance & Design
7 topics- IndexesIntermediate5m
- Execution PlansIntermediate5m
- Query OptimizationAdvanced5m
- ConstraintsAdvanced5m
- Primary and Foreign KeysAdvanced5m
- NormalizationAdvanced5m
- SQL SecurityAdvanced5m
Practice
2 topics- Practical ExercisesAdvanced5m
- Interview QuestionsAdvanced15m
Visual guides
1 diagramCode example
A taste of the track, from Database Fundamentals.
-- Which customers live in Pune?
SELECT CustomerId, Name, City
FROM Customers
WHERE City = 'Pune';
CustomerId Name City 1 Asha Pune 3 Meera Pune
Practice exercises
Write a query that returns the Name of every customer who lives in Delhi.
Start the container, connect, and create a database called Practice.
Add a Categories table (CategoryId, Name) and explain how Products would reference it instead of storing the category name.
Design columns for an Employees table: name, email, salary, date of joining, whether they are active, and a last-login timestamp.
Return the two cheapest products with their price, using an alias Cost for Price.
Find Electronics products that cost less than 1000.
Show all 30 exercises
List products from cheapest to most expensive, breaking ties by name.
Count how many orders each status has.
List categories whose total product value is under 20,000.
Insert a customer named Zoya from Jaipur and return the new CustomerId.
Mark order 103 as Delivered and show its old and new status.
Write a soft delete: add an IsDeleted BIT column to Products and “delete” the Pen.
List students who are NOT enrolled in any course.
List products that have been ordered at least once, using IN.
Use a CTE to find each customer’s number of orders, then return only customers with more than one order.
Return only the most expensive product in each category.
Return the total quantity of items sold across all orders.
Create a view vActiveProducts showing only Name and Price, then query it.
Call dbo.EnrollStudent from C# with ADO.NET and read the output parameter.
Write an inline TVF dbo.fn_OrdersByStatus(@status) returning OrderId and OrderDate.
Explain what inserted and deleted contain during a DELETE statement.
What would the balances be if XACT_ABORT were OFF and there were no TRY…CATCH, and the second UPDATE failed?
Design an index for: SELECT Name, Price FROM Products WHERE Category = @c ORDER BY Price.
A plan shows an Index Seek followed by 50,000 Key Lookups. What is the usual fix?
Rewrite WHERE LEFT(Name, 3) = 'Lap' to be SARGable.
Add a CHECK constraint to Orders allowing only Pending, Delivered or Cancelled statuses.
Recreate the OrderItems → Orders foreign key with ON DELETE CASCADE and explain the effect.
A Students table has columns Course1, Course2, Course3. Which normal form does it break and how would you fix it?
Grant a reporting role read-only access to a reporting schema.
Exercise 2: return each customer’s most recent order (customer name, order id, order date).
Common interview questions
- What is the difference between INNER JOIN and LEFT JOIN?
- WHERE vs HAVING?
- DELETE vs TRUNCATE vs DROP?
- Primary key vs unique key vs foreign key?
- What is a relational database?
- How do you choose data types for columns?
- In which order is a SELECT statement logically processed?
- How do you sort and page results?
- What do aggregate functions do with NULLs?
- Clustered vs non-clustered index?
- Do stored procedures prevent SQL injection?
- What is a CTE and when would you use one?
- Explain ROW_NUMBER, RANK and DENSE_RANK.
- What is normalization? Explain 1NF, 2NF and 3NF.
- View vs stored procedure vs function?
- How do you write a safe UPDATE or DELETE?
- Subquery vs JOIN — which should you use?
- What is a user-defined function, and when does it hurt performance?
- What does a transaction guarantee?
- Which constraints keep data valid?
- Natural keys vs surrogate keys?
- Explain transaction isolation levels.
- How do you tune a slow query?
- Why can triggers be problematic?
- How do you read an execution plan?
- What is parameter sniffing?
- How do you secure a SQL Server database used by an app?
- What are window function frames?