Advanced T-SQL Querying, Programming and Tuning for SQL Server

5 days / 40 hours | online / onsite

Developed by Lucient-co-founder Itzik Ben-Gan, the Advanced T-SQL course focuses on writing and tuning queries and programming with T-SQL in SQL Server 2019, 2022 and prior versions as well as in Azure SQL Database.

Download course description

What Does this Course Cover?

In this course you will learn the details and capabilities of T-SQL in the following areas: Logical Query Processing; Query Tuning (including tools for measuring query performance and Internals and Index Tuning); Subqueries and Table Expressions (Derived Tables, CTEs, Views, Inline Table-Valued Functions), Recursive Queries, the APPLY Operator, Joins and Set Operators; Data Analysis (including Window Functions, Pivoting and Unpivoting Data, aggregating strings with the STRING_AGG function); TOP and OFFSET-FETCH; Data Modification; Working with Date and Time (including System-Versioned Temporal Tables); Programmable Objects (including Dynamic SQL, User Defined Functions, Stored Procedures, Plan Caching, Transactions and Concurrency, Error Handling); In-Memory OLTP.

Along the course you will learn how to use T-SQL to solve practical problems such as: Relational Division, Missing and Existing Ranges (Gaps and Islands), Separating Elements, Pivoting and Unpivoting, Ranking and Offset, Running Totals, Moving Averages, YTD, Custom Aggregations, TOP and OFFSET-FETCH Problems, Paging, Top N Per Group, Median, Data De-Duplication, Handling Sequences, Merging Data, Treatment of Temporal Intervals (Intersection, Max Concurrent, Packing), Dynamic Search Conditions (aka Dynamic Filtering), considerations for using In-Memory OLTP, and more.

You will learn how to tune your queries, how to develop efficient routines including user defined functions and stored procedures, work in multi-user environments with transactions and isolation levels, and use dynamic SQL securely and efficiently.
The course provides a dedicated module focusing on query tuning. The module covers tools for measuring query performance and covers internals and index tuning. It also provides a lot of additional query tuning material for self-studying. Moreover, query tuning is in the heart of this course and is incorporated in the different modules throughout the course.

With each querying/programming task the discussions will revolve around logical aspects, set-based vs. iterative/procedural programming and optimization of the solutions.

The course workbook also contains a bonus self-study appendix on Graphs and Recursive Queries. This appendix covers graphs, trees and hierarchies. It explains how to model and
query such structures. It also covers the HIERARCHYID datatype, and the SQL Graph feature.

Next Dates

09/12/2024  – 13/12/2024; QA, online, delivered by Itzik Ben-Gan
14/04/2025  – 18/04/2025; QA, online, delivered by Dejan Sarka
18/08/2025  – 22/08/2025; QA, online, delivered by Dejan Sarka

For our classes managed by our partners QA (UK) or Cornerstone (Sweden) please visit their respective websites!

 

 

Course Outline

Module 01: Logical Query Processing
  • Logical Query Processing Order
  • Logical Query Processing Example
  • Phase Details
Module 02: Query Tuning
  • Tools for Measuring Query Performance
  • Internals and Index Tuning
Module 03 – Multi-Table Queries
  • Subqueries and Table Expressions
  • APPLY Operator
  • Joins
  • Set Operators

LAB 03

Module 04: Grouping, Pivoting and Windowing
  • Window Functions
  • Pivoting and Unpivoting Data
  • Custom Aggregations
  • STRING_AGG
  • Grouping Sets (bonus self-study unit)

LAB 04

Module 05: TOP and OFFSET-FETCH
  • TOP
  • OFFSET-FETCH
  • Top N Per Group

LAB 05

Module 06: Data Modification
  • Inserting Data
  • Sequences
  • Deleting Data
  • Updating Data
  • Merging Data
  • The OUTPUT Clause

LAB 06

Module 07 – Working with Date and Time
  • Date and Time Datatypes
  • Date and Time Functions
  • Date and Time Challenges
  • System-Versioned Temporal Tables
  • Date and Time Querying Problems

LAB 07

Module 08: Programmable Objects
  • Dynamic SQL
  • User Defined Functions
  • Stored Procedures
  • Triggers
  • Transactions and Concurrency
  • Exception Handling

LAB 08

Module 09: In-Memory OLTP
  • Intro to In-Memory OLTP
  • Architecture
  • Memory Optimized Tables and Indexes
  • Natively Compiled Procedures
  • Transaction Semantics

LAB 09

Appendix A: Graphs and Recursive Queries (Bonus Self-Study Material)
  • Graphs, Described
  • Materialized Paths
    • Custom
    • Using the HIERARCHYID datatype
  • Nested Sets
  • Nested Iterations
    • Loops
    • Recursive Queries
  • SQL Graph

LAB A

Author

Itzik Ben-Gan

Co-Founder & T-SQL Trainer

Itzik Ben-Gan is a T-SQL Trainer and Co-Founder of Lucient. A Microsoft Data Platform MVP (Most Valuable Professional) since 1999, Itzik has delivered numerous training events around the world focused on T-SQL Querying, Query Tuning and Programming. Itzik is the author of several books including T-SQL Fundamentals, T-SQL Querying and T-SQL Window Functions. He has a monthly column at sqlperformance.com. Itzik’s speaking activities include PASS summit, SQLBits and various user groups around the world. Itzik is the author of Lucient’s Advanced T-SQL and T-SQL Fundamentals courses along with being a primary resource within the company for their T-SQL related activities.

Course Materials

Each student will receive:
• A course Workbook
• A digital copy of Itzik Ben-Gan’s award-winning book T-SQL Querying (MSPress)
• A copy of the course’s source code

Audience

This course is intended for:
• T-SQL Developers, DBAs, BI Specialists, Data Scientists, Architects, and Analysts
• Those that need to write or review T-SQL code in SQL Server and Azure SQL

Prerequisites

Before attending this course, it is recommended that students have the following skills:
• At least one year of T-SQL querying and programming experience in SQL Server or
Azure SQL

Course Objectives

Upon completion of this course, the student will:
• Understand logical query processing
• Understand SQL Server’s internal data structures
• Be able to analyze and tune query performance
• Be able to analyze query execution plans
• Be able to solve complex querying and programming tasks
• Think in terms of sets
• Be able to compare set based and iterative solutions
• Use window functions to improve your solutions
• Handle date and time data including intervals
• Create system-versioned temporal tables
• Describe performance issues related to user defined functions and possible
workarounds
• Understand compilations, recompilations, plan caching and reuse
• Understand transactions and concurrency aspects of database programming
• Know how to handle hierarchical data and write recursive queries
• Understand the benefits of using memory optimized data
• Describe T-SQL enhancements in recent versions of SQL Server