The Joys of Early Exits

Erik Darling (Erik Darling Data)
850 views •

In this video, I dive into the concept of early exits in T-SQL code, particularly in stored procedures and triggers. I highlight how early exits can significantly improve query performance by avoiding unnecessary work when no data is found or when certain conditions are not met. By sharing practical examples and demonstrating how to implement these early exits, I aim to help you optimize your code and reduce unnecessary CPU usage. Whether you're a developer, a DBA, or just someone interested in query tuning, this video offers valuable insights that can be applied to your work. Additionally, I discuss the benefits of using free, open-source tools like Code.ErikDarling.com for monitoring SQL Server and PostgreSQL, and I share some exciting speaking engagements I have coming up at Pass Summit West. CHAPTERS 00:00:00 - Introduction 00:01:31 - Early Exits in Code 00:04:13 - Practical Examples 00:06:00 - Early Exits in Triggers 00:08:06 - Benefits of Early Exits 00:08:37 - Conclusion ━━━━━━━━━━━━━━━━━━━━━━━━━━ 🕵️‍♂️ FREE SQL SERVER MONITORING & Plan Analysis ━━━━━━━━━━━━━━━━━━━━━━━━━━ https://github.com/erikdarlingdata/PerformanceMonitor https://github.com/erikdarlingdata/PerformanceStudio https://plans.erikdarling.com/ ━━━━━━━━━━━━━━━━━━━━━━━━━━ 📚 TRAINING & COURSES ━━━━━━━━━━━━━━━━━━━━━━━━━━ Get AI-Ready With Erik https://training.erikdarling.com/get-ai-ready-with-erik?coupon=AIREADY SQL Server Performance Engineering Course https://training.erikdarling.com/sql-server-performance-engineering?coupon=ENGINEERING Learn T-SQL with Erik https://training.erikdarling.com/learn-t-sql-with-erik?coupon=ADVANCEDTSQL Everything Bundle: https://training.erikdarling.com/?coupon=SPRINGCLEANING ━━━━━━━━━━━━━━━━━━━━━━━━━━ 🛠️ CONSULTING & SERVICES ━━━━━━━━━━━━━━━━━━━━━━━━━━ Need SQL Server performance help? https://training.erikdarling.com/sqlconsulting ━━━━━━━━━━━━━━━━━━━━━━━━━━ 💬 CONNECT ━━━━━━━━━━━━━━━━━━━━━━━━━━ Ask questions at Office Hours https://erikdarling.com/officehours/ Become a channel member https://www.youtube.com/@ErikDarlingData/join

Keyboard shortcuts

On. Switch them off if they collide with your assistive tools; ? still opens this sheet.

Go to

Press g then the letter.

  • gh Latest
  • gs Sources
  • gm Media
  • gv Videos
  • gp Podcasts
  • gc Calendar
  • gd Decoder
  • gz Dataviz
  • ga Datasets
  • gb Blog
  • gk Markets
  • gj Careers
  • gn Prompt Notebook

On this page

  • / Focus search, where there is one
  • t Back to top
  • ? This list
  • Esc Close