Category: TSQL and SQL Client Code

When multiple sessions insert into the same table, and something unique is there (uq index, uq constraint), a “duplicate key” error (2601, 2627) occurs from time to time, almost inevitable. If your app is affected with intermittent “duplicate key” surprises, …

Insert if NOT exists – duplicate key problem Read More »

While ago I wrote SSMS Addin called SQL XDetails. It was not updated long time because GUI integration with new SSMS versions were different every time and too much for my poor csharp knowledge. I am a DB guy after …

sp_xdetails – index and table info Read More »

Tagged with: , , , , ,

Your SQL Server may be slow for a peculiar reason: a run-away query that pushes-out all other queries from the plan cache, like a huge wave. So called “tsunami query”. Tsunami query wipes other plans from the cache and makes your SQL running slow. Creating tsunami query is easy and usually not intentional: a developer concatenates values in SQL command string. As it “works on my machine”, it easily slips to production (nobody tests for this, right?), and the monster is loose!

Tagged with: , , ,

Introduction You developed a new TSQL code and want to check is there a slow SQL statement inside and which is it? Or you debug the code and want to know which statement throws error, maybe inside of a trigger …

SQL Profiler for Developers and Testers Read More »

Do you use ROWVERSION/TIMESTAMP to pull changed data? If you do, you might experience a problem – not all changed rows are pulled, some are skipped. How can that be, if we pulled entire range of rowverion changes with no …

ROWVERSION/TIMESTAMP skipping rows problem Read More »

Tagged with: , , , ,

Introduction Demonstration of the smallest possible deadlock: only one statement, one table, one row. Without transactions (no BEGIN TRANSACTION). Even RCSI (Read Committed Snapshot Isolation) is turned ON to eliminate shared locks. Everything is “by the book” as Books Online …

Single-Row Deadlock Read More »

Tagged with: ,

In almost every database we have a process that filters the same data with different filters. Typically, query is within a stored procedure that has many filtering parameters that are optional. The problem is – a query optimized builds only ONE plan that will handle every filter combination you throw at it.

Tagged with: , , ,

How do I format my TSQL code? Everybody has it’s own preferences on formatting SQL or TSQL code. I follow few very simple rules to achieve better readability, less bugs and  – you wont’ believe – faster code execution! Code …

Formatting TSQL code Read More »

Properly closing a connection to Sql Server in DotNet is more challenging than one might think. Classic code looks something like this MSDN example:

Tagged with: , ,

ADO.Net Data Provider for SQL Server (System.Data.SqlClient namespace in System.Data.dll assembly) has two common classes we often use: SqlConnection and SqlCommand. SqlCommand class has CommandTimeout property (do not mix it with the ConnectionTimeout which stops long login process). But, do …

CommandTimeout – How to handle it properly? Read More »

Tagged with: ,
Visit Us On TwitterVisit Us On FacebookCheck Our FeedVisit Us On LinkedinVisit Us On Youtube