Development

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

The SQL Language is Just a Hurdle You Gotta Overcome.

T-SQL
33 Comments
I’m not talking just about Microsoft SQL Server specifically here, nor T-SQL. Let’s zoom out a little and think bigger picture for a second: is the SQL language itself a problem? Sometimes when I talk to client developers, they gripe about the antiquated language. The order of a SELECT statement doesn’t make any sense. You…
Read More

Coming in Entity Framework 9: Better Query Parameterization

Development
22 Comments
Hallelujah. With current versions of Entity Framework, when developers add a mix of parameters and specific values to their query like this: C# async Task<List<Post>> GetPosts(int id) => await context.Posts .Where( e => e.Title == ".NET Blog" && e.Id == id) .ToListAsync(); 12345 async Task<List<Post>> GetPosts(int id)    => await context.Posts        .Where(            e => e.Title == ".NET Blog" &&…
Read More

Using ChatGPT for T-SQL Code Reviews

T-SQL
23 Comments
For this month’s T-SQL Tuesday, Pinal Dave asked us if AI has helped us with our SQL Server jobs. For me, there’s been one instant, clear win: code reviews. I usually keep a browser tab open with ChatGPT 4, and I paste this in as a starting point: You are an experienced, diligent database developer…
Read More

Does Your GROUP BY Order Matter?

Execution Plans
5 Comments
Sometimes when you do GROUP BY, the order of the columns does matter. For example, these two SELECT queries produce different results: Transact-SQL CREATE INDEX Location_DisplayName ON dbo.Users(Location, DisplayName); SELECT TOP 100 Location, DisplayName, COUNT(*) AS Duplicates FROM dbo.Users GROUP BY Location, DisplayName ORDER BY Location, DisplayName; SELECT TOP 100 DisplayName, Location, COUNT(*) AS Duplicates…
Read More