Development

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

Geographic Sharding is Usually a Pretty Bad Idea.

Development
1 Comment
Let’s say you built a web app and it became globally popular. You’ve got users scattered across North America, Europe, and Asia. In theory, you could shard your data globally: build 3 sets of SQL Servers, one on each continent, and split up their data. In reality, this usually creates more problems than it solves.…
Read More

Query Exercise: What Makes SELECT TOP 1 or SELECT MAX Different?

Query Exercises
10 Comments
These two queries both get the same answer from the Stack Overflow database: Transact-SQL SELECT TOP 1 LastAccessDate FROM dbo.Users ORDER BY LastAccessDate DESC; SELECT MAX(LastAccessDate) FROM dbo.Users; 123456 SELECT TOP 1 LastAccessDate    FROM dbo.Users    ORDER BY LastAccessDate DESC; SELECT MAX(LastAccessDate)    FROM dbo.Users; But do they go about their work the same way? As it turns out, no –…
Read More

Query Exercise: Fix This Computed Column.

Query Exercises
54 Comments
Take any size of the Stack Overflow database and check out the WebsiteUrl column of the Users table: Sometimes it’s null, sometimes it’s an empty string, sometimes it’s populated but the URL isn’t valid. Let’s say that along the way, someone decided to ask ChatGPT to build a function to check for valid website URLs,…
Read More

Does Bit Column Order Matter in Tables?

Development
3 Comments
At the PGConf.dev, where Postgres developers get together and strategize the work they wanna do for the next version, I attended a session where Matthias van de Meent talked about changing the way Postgres stores columns. As of right now (Postgres 17), columns are aligned in 8-bit intervals, so if you create a table with…
Read More