Recording Debugging Information Inside a SQL Server Function Call

We cannot use PRINT or RAISERROR statements within a T-SQL function body for debugging purposes. This article presents a workaround using session context.
We cannot use PRINT or RAISERROR statements within a T-SQL function body for debugging purposes. This article presents a workaround using session context.
Two ways to access a SQL Server table variable outside its declaration scope.
How to avoid unnecessary stored procedure compilation and plan cache pollution when using shared SQL Server temporary tables. Includes an alternate implementation using API cursors without row-by-row processing.
Contrary to the product documentation, SQL Server cursor variables can be used to share data between stored procedures in the input or output direction (but not both).
How to split a large update operation into batches using a SQL Server API cursor.
How to split a large delete operation into batches using a SQL Server API cursor.
Details of an incorrect results bug with TOP PERCENT
when used with correlated parameters, and how Microsoft chose to address it.
A bug with MERGE
that causes SQL Server to try to update a non-existent row, leading to database corruption or a retail assertion, stack dump, and connection termination.
Exploring the internal layout of a Lazy Index Spool's worktable, answering how it distinguishes a NULL result from an empty one.
The SQL Server Segment Apply optimizer feature and how it is implemented in GenGbApplySimple, GenGbApplyAgg, and BuildGbApply.
Internal and less well-known SQL Server details about prepared statements and sp_executesql
SQL Server parameter sniffing when using sp_prepare
or sp_prepexec
in T-SQL.
Documenting some of the internal thresholds used when deciding whether to apply the Parameter Sensitive Plan Optimization in SQL Server 2022.
SQL Server batch mode operators produce batches containing between 64 and 900 rows. How then can a batch mode operator produce more batches than rows?
SQL Server resumable index operations may be very slow when resumed after the transaction log runs out of space.
An example of poor update performance under RCSI as compared with locking read committed. Details of an improvement in SQL Server 2022 that can help avoid the worst effects.
A 16-year old SQL Server bug that means 'forced plans' have the query plan hash in place of the expected query hash. Includes an explanation and discussion of the term 'morally equivalent plan'.
I was asked recently why Halloween Protection was needed for data modification statements that include a self-join of the target table. This gives me a chance to explain, while also covering some interesting product bug history from the SQL Server 7 and 2000 days.