TSQL Tuesday #99: Tabs vs Spaces

February 13, 2018 Andy 3

The great tabs vs spaces debate is often framed as a matter of opinion or coding style. “As long as you’re consistent, it doesn’t matter.” Keep in mind that unlike your choice in footwear, coding style can’t be personal. I’m going to draw a line in the sand and say that tabs, like Crocs and mullets, are bad style.

Parsing file names from paths using T-SQL

January 17, 2018 Andy 14

SQL Server is great at a lot of things. I spend a lot of time blogging about all the cool things that SQL Server does. But (you knew there was a “but”, didn’t you) SQL Server isn’t great at everything. Lets write about something that … [Read More]

Finding active transactions

January 2, 2018 Andy 1

Have you ever forgot to commit a transaction? Maybe you’ve even left for lunch and caused a problem while you were gone. Uncommitted transactions can cause all sorts of problems–not just blocking, but it can affect your Availability Groups & Mirroring, your TempDB version store … [Read More]

Finding the Leader Blocker

October 26, 2017 Andy 12

During the course of normal processing in a database, blocking happens. Blocking is “by design” because your database is on ACID. In an OLTP database, most of your transactions are short in duration, so we expect blocking to also be short in duration. If blocking … [Read More]

Add-Equals operator

May 24, 2016 Andy 9

Shortcuts & tips from an Impatient DBA This series of short posts will demonstrate some lesser-known features, keyboard shortcuts, and other tips that make my day as a DBA more productive. None of these are groundbreaking super-secret features–they are the little things that I do … [Read More]

How to shrink a database in 4 easy steps

April 28, 2016 Andy 9

It’s a really common question: “How do I shrink my database?” Luckily, there’s also a really common answer: “Don’t.” …but what if you really have to? Perhaps you just implemented data compression, and have 60% free space in your database. Perhaps you just deleted a … [Read More]

CONVERT() to float using scientific notation

April 20, 2016 Andy 1

Someone posted to #sqlhelp on Twitter, asking the following: “Wondered if anyone could enlighten me as to why ISNUMERIC(‘7d8’) returns 1?” Sure enough, SELECT ISNUMERIC(‘7d8′) returns a 1. WTF? d isn’t numeric! OK, sure, if you say “seven-dee-eight” out loud it sounds like a number, but “d” is a … [Read More]

No Picture

Decoding sql_handle

February 29, 2016 Andy 0

If you’ve ever looked at sys.sysprocesses or sys.dm_exec_requests (or a number of other DMVs), you’ve noticed there is a column called “sql_handle” that contains some binary gobbledygook. Books Online gives the (un)helpful definition as “Hash map of the SQL text of the request.” sp_WhoIsActive In … [Read More]

No Picture

sp_executesql with output parameters

January 22, 2015 Andy 2

One of my coworkers asked me about output parameters from dynamic SQL today. I pointed him at sp_executesql, which allows for passing parameters into or out of dynamic SQL. The syntax can be confusing at first blush (especially for a new DBA or developer), but … [Read More]