Development

it hurts so good, I don't understand

The Query Tuning Trick You Should Use More: Pagination

T-SQL
6 Comments
When I’m tuning queries, the normal answer is to make the query perform better – either via changing the T-SQL, adding hints, or adding indexes so that the data’s better prepared for the query. However, sometimes when I’m looking at the output of sp_BlitzCache, I scroll across to the Average Rows column and double-check that…
Read More
Mastering Query Tuning

Mastering Class Updates on Resource_Semaphore, The Ascending Key Problem, and The Cloud

Development
2 Comments
I’ve posted a couple of updated videos to my Mastering courses. In Mastering Server Tuning, I updated and expanded the RESOURCE_SEMAPHORE module to cover more details about query workspace grants, plus cover SQL Server 2022’s updates to Adaptive Memory Grants. In Mastering Query Tuning, I added a new module on the Ascending Key Problem. It’s…
Read More
The Dude Abides

Query Exercise Answers: Returning Routes in the Right Order

In your most recent Query Exercise challenge, I gave you these two tables: Transact-SQL DROP TABLE IF EXISTS dbo.Stations; CREATE TABLE dbo.Stations (StationId INT IDENTITY(1,1) PRIMARY KEY CLUSTERED, StationName VARCHAR(50), StationPhysicalOrder INT); INSERT INTO dbo.Stations (StationName, StationPhysicalOrder) SELECT CHAR(64 + n), n FROM (VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11), (12),(13),(14),(15),(16),(17),(18),(19) ) AS Numbers(n); DROP TABLE IF EXISTS dbo.StationRoutingOverride; CREATE…
Read More

Query Exercise: Looking for Email Addresses

Query Exercises
12 Comments
“They put their password WHERE?!?” Personally identifiable information (PII) is freakin’ everywhere. When companies first start looking to identify and lock down their data, they think it’s going to be as easy as identifying common columns like EmailAddress, DateOfBirth, SocialSecurityNumber, and so forth. They think, “We’ll just encrypt those columns and we’ll be fine.” Ho…
Read More
Local project

How to Use Github in SSMS v21

SQL Server Management Studio v21 added native Git support, making it easier to use source control natively inside SSMS. This feature is for developers who are already used to working with Github to manage specific object changes as they work, and who are already accustomed to Git terminologies like branches, commits, pushes, and pulls. This…
Read More

Should That Be One Update Statement or Multiple?

T-SQL
12 Comments
Let’s say we have a couple of update statements we need to run every 15 minutes in the Stack Overflow database, and we’ve built indexes to support them: Transact-SQL EXEC DropIndexes @TableName = N'Users'; CREATE INDEX LastAccessDate ON dbo.Users(LastAccessDate); CREATE INDEX AccountId ON dbo.Users(AccountId); GO BEGIN TRAN /* Give reputation points if folks did something…
Read More

Yes, Cardinality Estimation Keeps Changing After SQL Server 2014.

Execution Plans
4 Comments
About 10 years ago, Microsoft made changes to the Cardinality Estimator (CE) which caused some problems for SQL Server upgrades. When folks upgraded to SQL Server 2014, they also casually switched their databases’ compatibility level to the latest version, because for years that hadn’t really affected query plans. They just figured they wanted the “latest…
Read More

TRY/CATCH Doesn’t Always Work.

T-SQL
11 Comments
If you’re using TRY/CATCH to do exception handling in T-SQL, you need to be aware that there are a lot of things it doesn’t catch. Here’s a quick example. Let’s set up two tables – bookmarks, and a process log to track whether our stored proc is working or not: Transact-SQL DROP TABLE IF EXISTS dbo.Bookmarks;…
Read More