Spatial unions merge shapes that touch or overlap into one shape. This post uses six land parcels on a flat grid to show STContains, STUnion for two shapes, chained unions, UnionAggregate with GROUP BY, and CollectionAggregate for comparison. Every area and result comes from SQL Server 2025.
Aggregate and Detail Columns in One Query: GROUP BY or OVER
Aggregate and detail columns in one query fail with Msg 8120 until you pick a way to keep the rows. This post compares GROUP BY, a scalar subquery and OVER on one small table, adds PARTITION BY and a share of the total, and then combines GROUP BY with OVER. Every result comes from SQL Server 2025.
Why We Use Code Comments in SQL Server: Say Why, Not What
Why we use code comments comes down to one habit: write the reason, not the action. This post uses a small library table to show single-line and block comments, commenting out a join to test a theory, the Msg 156 trap, nested comments, and whether comments slow a query. Every result comes from SQL Server 2025.
QUERY_OPTIMIZER_HOTFIXES: Turning On Optimizer Fixes per Database
A vendor says to turn on optimizer hotfixes. Here is how I check the setting, try it on one statement, and restore it.
Restore a Database in SSMS: Step by Step
To restore a database in SSMS, right-click Databases, choose Restore Database, pick the backup file, name the destination and choose the recovery state. This post covers each page of the dialog, the tail-log error that stops overwrites, and the T-SQL for a full, differential and log restore chain.
SQL Server Version and Edition: SQL in Sixty Seconds #043
To find the SQL Server version and edition, read SERVERPROPERTY instead of parsing @@VERSION. The tests here show every useful property on SQL Server 2025, why ProductLevel can say RTM after an update, and how to read the version from the ERRORLOG.
SQL SERVER – Primary Key and NonClustered Index in Simple Words
In 2006 I wrote how Primary Key and Unique Key differ. Now I fill the gap and explain primary key and nonclustered index in simple words.






