Problems displaying this newsletter? View online.
SQL Server Central
Featured Contents
Question of the Day
 
The Voice of the DBA
 

Finding Bad Queries

T-SQL Tuesday #200 was in July, hosted by Brent Ozar, and it was a great topic: How do you recognize a bad query? In the age of AI, when lots of people will get queries written by others (people or AIs), how can you easily and quickly review code? Review is already a challenge in the software world, and I am sure it's going to be even more challenging as people let machines author more database code.

Lots of you might hope that an AI agent will write better code than your average developer, but I don't know if I'd count on that. There is a ton of poor query examples on the Internet and that's where AI models are changed. You need some sort of feedback look, good testing, and strong guidance. I think it's as likely as not that AIs will produce poor queries just like humans.

Just faster.

How can you recognize poor queries? How do you judge if there are issues? Brent's roundup shows what a number of people think, and there are some good "quick checks" to use to evaluate your code. The things that people wrote in their blog posts are the types of things that I'd want added to Flyway's Code Analysis rules to catch problems before they get deployed to production. After all, anything that gets to production usually lives for 10 years (my rule of thumb).

Getting feedback early in the development process is critical. We know from over 50 years of software development that finding problems early is less expansive than finding them later. Whether we use humans or AI agents, we don't want unnecessary time spent on simple bad code things that we know cause issues. Shift-left is still a challenge, even in the automated era of DevOps and guided AI agent skills. We need reliable, repeatable ways to analyze code and limit the downstream effects of poor quality.

Especially these days where the volume of changes is overwhelming CI/CD systems. This was a problem already in organizations with too many teams in one codebase. It's a growing problem in more organizations as users use AI and submit more changes.

Plus wasting time gets expensive. Human labor is slow and spending time on more tokens for rework gets expensive.

Don't let bad queries flow through to CI/CD systems if you can avoid it. Learn to provide quick feedback early to whoever, or whatever, writes your SQL.

Steve Jones - SSC Editor

Join the debate, and respond to today's editorial on the forums

 
 
 Featured Contents
SQLServerCentral Article

Advanced T-SQL: Replacing Slow Cursors with Window Functions

sabyda from SQLServerCentral

This article looks at replacing a cursor with a window function to improve performance.

Technical Article

Database Animations: You’ve Heard of Page Splits. Here’s What They Really Mean.

Additional Articles from SQLServerCentral

You've heard that page splits are bad, and they're an indication that your table design is making your storage work too hard. You've heard that the right answer to fix it is adjusting fill factor lower, or doing regular index maintenance.

Blog Post

From the SQL Server Central Blogs - Power BI Performance in 2026: A Practical Guide to Faster Semantic Models and Reports

James Serra from James Serra's Blog

Originally published April 2022; substantially updated July 2026. This post is a complete replacement for and update to my April 2022 post, Power BI Performance Features. That post focused...

Blog Post

From the SQL Server Central Blogs - Getting Started with Azure SQL Developer on Macbook

MarlonRibunal from Marlon Ribunal - SQL, Code, Coffee, etc.

The idea behind Azure SQL Developer is for anyone to build, iterate, and test locally at no cost. This means NO Azure subscription to deal with and NO credit...

Fundamentals of Data Engineering: Plan and Build Robust Data Systems

Site Owners from SQLServerCentral

Data engineering has grown rapidly in the past decade, leaving many software engineers, data scientists, and analysts looking for a comprehensive view of this practice. With this practical book, you'll learn how to plan and build systems to serve the needs of your organization and customers by evaluating the best technologies available through the framework of the data engineering lifecycle.

 

 Question of the Day

Today's question (by Steve Jones - SSC Editor):

 

The Service Name

What does @@servicename() return?

Think you know the answer? Click here, and find out if you are right.

 

 

 Yesterday's Question of the Day (by Steve Jones - SSC Editor)

BIT_COUNT() IV

In SQL Server 2025, I run this code:

select bit_count('A')

What is returned?

Answer: An error

Explanation: The digital value in bits of A is 65, which is 01000001. However, BIT_COUNT() doesn't support values that don't implicitly cast to numeric or binary values. Ref: BIT_COUNT() - https://learn.microsoft.com/en-us/sql/t-sql/functions/bit-count-transact-sql?view=sql-server-ver17

Discuss this question and answer on the forums

 

 

 

Database Pros Who Need Your Help

Here's a few of the new posts today on the forums. To see more, visit the forums.


General
PowerBI Question - Data Sources - I don't see a PowerBI forum, so I'm posting here. I have a need to create a report using one query but multiple SQL Servers. I'm wondering if I could create a CMS registered group and somehow pass the query to all servers in the group at the same time and pull back the results […]
Editorials
Make It Routine - Comments posted to this topic are about the item Make It Routine
AI Observability Challenges in FinOps as a DBA - Comments posted to this topic are about the item AI Observability Challenges in FinOps as a DBA
Another Model, More Data Loss - Comments posted to this topic are about the item Another Model, More Data Loss
What is CPU Usage? - Comments posted to this topic are about the item What is CPU Usage?
Article Discussions by Author
DBCC CHECKDB Limits III - Comments posted to this topic are about the item DBCC CHECKDB Limits III
CROSS APPLY Fundamentals: Part 1 - Comments posted to this topic are about the item CROSS APPLY Fundamentals: Part 1
SQL Agent Job Automated Change Capture Process - Comments posted to this topic are about the item SQL Agent Job Automated Change Capture Process
Finding a Database Master Key - Comments posted to this topic are about the item Finding a Database Master Key
Can You Really Downgrade from Enterprise to Standard and Save Thousands? Here's What Happened - Comments posted to this topic are about the item Can You Really Downgrade from Enterprise to Standard and Save Thousands? Here's What Happened
Limiting Checkpoints - Comments posted to this topic are about the item Limiting Checkpoints
SQL Server Certificates - Comments posted to this topic are about the item SQL Server Certificates
Connect an Azure Function to Azure SQL database Using a Managed Identity - Comments posted to this topic are about the item Connect an Azure Function to Azure SQL database Using a Managed Identity
SQL Server 2022 - Administration
Migration Challenge: Excessive FULLSCAN Statistics Update Duration Blocking SQL - Hello everyone , I am planning to migrate a database from SQL Server 2014 to SQL Server 2019. The migration process includes a double-run, and one of the steps in the timeline is an UPDATE STATISTICS with FULLSCAN. This operation takes more than three days, which makes the cutover impossible because such a delay is […]
SQL 2025 SSMS Nonsense - Yeah, I know this is a 2022 forum, but I don't see a 2025 forum at the moment. I downloaded 2025 Developer Standard edition and 2025 SSMS. I right click my database to import an excel sheet and "Import Data" is greyed out. Did my Google-Fu and found out that SSIS needs to be installed […]
 

 

RSS FeedTwitter

This email has been sent to {email}. To be removed from this list, please click here. If you have any problems leaving the list, please contact the webmaster@sqlservercentral.com. This newsletter was sent to you because you signed up at SQLServerCentral.com.
©2019 Redgate Software Ltd, Newnham House, Cambridge Business Park, Cambridge, CB4 0WZ, United Kingdom. All rights reserved.
webmaster@sqlservercentral.com

 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -