Live classes start in 2d 07h 57m — Save your seat

T-SQL Code Quality and Query Patterns

Maintainable T-SQL and patterns that avoid correctness and performance problems.

106 associated posts102 primary posts

T-SQL & Development

Give Your T-SQL a Semicolonoscopy

In theory, all of your T-SQL statements are supposed to end with a semicolon, like this: [crayon-6ae53e3139e7b370031209/] Why? Well, SQL Server 2005's Books Online says: Many code examples use a semicolon (;) as a Transact-SQL statement terminator. Although the semicolon is not required, using it is considered a good practice. You know, like flossing your teeth,…

Read more about Give Your T-SQL a Semicolonoscopy 39 comments — Join the discussion
T-SQL & Development

Window Functions and Cruel Defaults

My First Post Here...
Well, my first technical post, was about how the default index creation method is OFFLINE. If you want that sweet, sweet Enterpri$e Edition ONLINE goodness, you need to specify it. It's been a while since that one; almost six months to the day. So here's another one!
But Window Functions Are Awesome
Heck yeah they are. And how. Boy howdy. Etc. You get the point. I'm enthusiastic. What can be cruel about them? Glad you asked!

Read more about Window Functions and Cruel Defaults 5 comments — Join the discussion
T-SQL & Development

The Top 3 Mistakes T-SQL Developers Make

Over the years, I've done all kinds of awful things with T-SQL and made countless mistakes. Some were harmless; others were borderline catastrophic (exciting times!). I was curious what kind of horrible mistakes other people make, so I threw the question out to Twitter. Every answer I got was unique, which was both telling (so…

Read more about The Top 3 Mistakes T-SQL Developers Make 31 comments — Join the discussion

Why You Simply Must Have a Date Table [Video]

As a developer, one of the things I can no longer live without is a date table. Who wants to type DATENAME and DATEPART over and over again? Not this guy, and once you have a date table, you won't want to either.

In this 16-minute video, I'll give you four reasons why you should stop writing so many date functions and concatenations, and start looking them up in a table instead.

Read more about Why You Simply Must Have a Date Table [Video] 24 comments — Join the discussion
T-SQL & Development

Refactoring T-SQL with Windowing Functions

You've been querying comparative numbers like Year To Date and Same Period Last Year by using tedious CTEs and subqueries. Beginning with SQL Server 2012, getting these numbers is easier than ever! Join Doug for a 30-minute T-SQL tune-up using window functions that will cut down dramatically on the amount of code you need to write.

Read more about Refactoring T-SQL with Windowing Functions 6 comments — Join the discussion

Mix and Match Databases: Dealing with Data Types

Moving between databases is hard enough, try using multiple databases in the same application and you might start thinking you've gone insane. Different application demands for accessibility, redundancy, backwards compatibility, or interoperability make this a possibility in the modern data center. One of the biggest challenges of running a heterogeneous database environment is dealing with a world of data type differences. There are two main ways to work through this situation:

Read more about Mix and Match Databases: Dealing with Data Types 3 comments — Join the discussion

Is Your Code an English Garden or Ikebana?

Erika loves having fresh flowers around the house. Every Saturday morning, I pick up a bouquet at a farmer's market or grocery store and put it in a vase for her. I'm slowly upping my game by learning more and more about the art of arranging flowers.

When I say flowers, I bet you think about the English Garden style: a big, complex vase with all kinds of flowers crammed into every nook and cranny. It's an explosion of color and life.

Read more about Is Your Code an English Garden or Ikebana? 3 comments — Join the discussion
T-SQL & Development

7 Things Developers Should Know About SQL Server

Hi.  I'm a former developer who's moved into database administration, and here's what I wish somebody would have told me when I got started.
7. SQL functions rarely perform well.
Good developers like to reuse code by putting it into functions, and then calling those functions from multiple places.  That's a great practice in the app tier, but it has huge performance drawbacks in the database tier.

Read more about 7 Things Developers Should Know About SQL Server 164 comments — Join the discussion

When a Query Isn’t Quite a Query

Databases exist to store data and answer questions about that data. The way we ask questions has to change based on the database itself - SQL changes between different RDBMS vendors. Things get even stranger when you venture outside the RDBMS world and start storing your data in Hive. Even though Hive Query Language (HiveQL) looks like SQL, there are some subtle but important differences to querying that first timers will want to keep in mind.

Read more about When a Query Isn’t Quite a Query 2 comments — Join the discussion