Tsql

Tag: tsql

Tracing Deadlock Graphs: Extended Events or Server Side Trace

Tracing Deadlock Graphs: Extended Events or Server Side Trace

Deadlock graphs are incredibly helpful for figuring out why queries are getting automatically killed off by SQL Server.

Continue reading

Testing an Insert for Race Conditions with Ostress.exe

Testing an Insert for Race Conditions with Ostress.exe

Whenever we have multiple sessions modifying data, things get tricky. When we have a pattern of “check if the data exists and then do a thing,” multiple sessions get even more complicated.

Continue reading

The Case of the Blocking Merge Statement (LCK_M_RS_U locks)

The Case of the Blocking Merge Statement (LCK_M_RS_U locks)

Recently I got a fun question about an “upsert” pattern as a “Dear SQL DBA” question. The question is about TSQL, so it lent itself to being answered in a blog post where I can show repro code and screenshots.

Continue reading

How to Script Out Indexes from SQL Server

How to Script Out Indexes from SQL Server

Sometimes you need to script out all the indexes in a database. Maybe you’re concerned something has changed since they were last checked in. Or maybe the indexes aren’t checked into source control, and you’re working on fixing that. (Important!)

Either way, sometimes you need to do it, and it’s not fun through the GUI. I needed to write some fresh demo code for this recently, and I needed it to give the details for partitioned tables using data compression, and I thought I’d share.

Continue reading

Why ROWLOCK Hints Can Make Queries Slower and Blocking Worse in SQL Server

Why ROWLOCK Hints Can Make Queries Slower and Blocking Worse in SQL Server

on February 4, 2016

Sometimes when SQL Server gets slow, developers and DBAs find that the problem is blocking.Β After lots of work to identify the query or queries which are the blockers, frequently one idea is to add ROWLOCK hints to the queries to solve the problem or to disable PAGE locks on theΒ table. This often backfires - here’s why.

Continue reading

How to Check if an Index Exists on a Table in SQL Server

How to Check if an Index Exists on a Table in SQL Server

on January 28, 2016

Category: indexing

It seems like this should be easy. But it’s not.

Continue reading

Filling in Data Potholes Redux: Tally Tables vs CTEs

Filling in Data Potholes Redux: Tally Tables vs CTEs

on January 4, 2011

In A Previous Installment… our heroine (that’s me) rediscovered CTEs, specifically in the recursive style. That was in my post “Filling in Data Potholes with Recursive CTEs.”

Continue reading