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.
Finding Orphaned Data and Log Files Nobody Attached
Inventory orphaned data and log files by comparing data-folder contents with sys.master_files, then review candidates before cleanup.
Safe Dynamic SQL With sp_executesql and QUOTENAME
Write safe dynamic SQL with typed value parameters, validated object names, and allowed sort columns, then test hostile input.
Optimized Locking in SQL Server 2025: What Changes for Blocking
Enable optimized locking in SQL Server 2025 with ADR and RCSI, then compare lock counts and blocking while checking LAQ limits.







