Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
SQL Query Design Patterns and Best Practices

You're reading from   SQL Query Design Patterns and Best Practices A practical guide to writing readable and maintainable SQL queries using its design patterns

Arrow left icon
Product type Paperback
Published in Mar 2023
Publisher Packt
ISBN-13 9781837633289
Length 270 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (6):
Arrow left icon
Chi Zhang Chi Zhang
Author Profile Icon Chi Zhang
Chi Zhang
Steven Hughes Steven Hughes
Author Profile Icon Steven Hughes
Steven Hughes
Shabbir Mala Shabbir Mala
Author Profile Icon Shabbir Mala
Shabbir Mala
Dennis Neer Dennis Neer
Author Profile Icon Dennis Neer
Dennis Neer
Leslie Andrews Leslie Andrews
Author Profile Icon Leslie Andrews
Leslie Andrews
Ram Babu Singh Ram Babu Singh
Author Profile Icon Ram Babu Singh
Ram Babu Singh
+2 more Show less
Arrow right icon
View More author details
Toc

Table of Contents (21) Chapters Close

Preface 1. Part 1: Refining Your Queries to Get the Results You Need
2. Chapter 1: Reducing Rows and Columns in Your Result Sets FREE CHAPTER 3. Chapter 2: Efficiently Aggregating Data 4. Chapter 3: Formatting Your Results for Easier Consumption 5. Chapter 4: Manipulating Data Results Using Conditional SQL 6. Part 2: Solving Complex Business and Data Problems in Your Queries
7. Chapter 5: Using Common Table Expressions 8. Chapter 6: Analyze Your Data Using Window Functions 9. Chapter 7: Reshaping Data with Advanced Techniques 10. Chapter 8: Impact of SQL Server Security on Query Results 11. Part 3: Optimizing Your Queries to Improve Performance
12. Chapter 9: Understanding Query Plans 13. Chapter 10: Understanding the Impact of Indexes on Query Design 14. Part 4: Working with Your Data on the Modern Data Platform
15. Chapter 11: Handling JSON Data in SQL Server 16. Chapter 12: Integrating File Data and Data Lake Content with SQL 17. Chapter 13: Organizing and Sharing Your Queries with Jupyter Notebooks 18. Index 19. Other Books You May Enjoy Appendix: Preparing Your Environment

What this book covers

The book is organized into four parts, with multiple chapters in each part. The book is designed to grow your experience from beginning to end if you choose to read it in that fashion. One of the greatest values is that each chapter is self-standing and can be used as a reference if you come across a situation where you need to improve your query writing specifically with that scenario. This also allows you to engage this book at whichever point makes the most sense for your query writing capabilities and skills.

In Chapter 1, Reducing Rows and Columns in Your Result Sets, the focus is on reducing your rows and columns to build an efficient dataset that can be used in reporting and other use cases.

The focus shifts to aggregating your results in Chapter 2, Efficiently Aggregating Data in Your Results. You can return a much more refined dataset that is easier to consume by effectively aggregating results to the right granularity in the content you need to pass along.

In Chapter 3, Formatting Your Results for Easier Consumption, the focus shifts to formatting your results. Often when working with data coming from a database, it must support levels of granularity or specific types of data to be efficient or inclusive. However, this comes at the price of storing data in a format that is not necessarily conducive to end users. Common formatting difficulties include handling currencies and dates. In this chapter, you will learn how to effectively format your data for more efficient use outside the database.

We expand on query efficiency by using conditional SQL in Chapter 4, Manipulating Your Data Results Using Conditional SQL. This will allow you to refine results even further for your end user. SQL Server supports several conditional logic statements that will be explored in this chapter.

Chapter 5, Using Common Table Expressions, delves into the world of common table expressions (CTEs) as they are commonly referred to. This technique is used to reduce subqueries and support other complex scenarios. In this chapter, you will learn how to build efficient CTEs to solve complex business problems.

Chapter 6, Analyze Your Data Using Window Functions, introduces you to window functions inside SQL. These functions allow you to do inline query aggregations or other techniques, such as row numbers. Some of the problems that are solved using window functions include building and running totals in your results.

Chapter 7, Reshaping Your Data with Advanced Techniques, dives into advanced techniques for reshaping your data. This includes handling hierarchical data and working with the PIVOT and UNPIVOT commands.

Chapter 8, Impact of SQL Security on Query Results, helps you deal with the impact of security on your query results. Citizen developers are often unaware of the impact security might have on the data they are pulling into their results. This chapter looks at the various implications of security and how to understand that impact on the results that you get and deliver to your end user.

Chapter 9, Understanding Query Plans, describes how to understand query plans. In this chapter, you will be introduced to the query plan itself and how to read it to determine what you can do to improve the performance and the query that you’re writing.

We then move on to understanding the impact of indexes on your query design in Chapter 10, Understanding the Impact of Indexes on Your Query Design. While we will not dive into authoring indexes, understanding the impact of indexes, including which indexes will improve your query performance, is the focus here. This will help you communicate your index needs to those that own the database design.

JSON data or NoSQL data has been disruptive to SQL writers around the world. In Chapter 11, Handling JSON Data in SQL Server, we will walk through the various functions and capabilities of SQL in SQL Server that supports JSON.

In Chapter 12, Integrating File Data and Data Lake Content with SQL, we will walk through techniques to integrate file and data lake content in your queries. This more complex technique is becoming very necessary in the new modern data platform.

We then have Chapter 13, Organizing and Sharing Your Queries with Jupyter Notebooks, covering Jupyter notebooks. Jupyter notebooks are available in Azure Data Studio and Synapse Workspace. These notebooks can be used to organize and share queries and their results more efficiently than SQL Server Management Studio (SSMS). In this chapter, we will walk you through notebook creation and sharing.

In the Appendix, Preparing Your Environment, we will walk you through setting up your environment to support the exercises in this book.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime