T-SQL Tuesday #83: Why Leave Well Enough Alone?
It’s 2016. So why are we still dealing with T-SQL code and design patterns that were designed 7 versions ago?
In the 15 years I have been using databases professionally, we’re still dealing with:
- Peoples’ names are split into first name, last name and middle initial fields. Ignoring that this falls afoul of several of the myths programmers believe about names, the first name column was defined as CHAR(10) in a standard installation. How many characters are in the name Christopher (hint: I had to take off a shoe to count them all)?
- Other arbitrarily short column sizes which cause problems as the system scales out in usage. For example, an event ID field that’s 8 characters: 2 letters and a 6-digit number which is used as a sequence. Guess what happens when you hit the millionth event in that sequence.
- Processes originally developed as transactions (for good reasons), but not designed in such a way that they scale to today’s demands.
NOLOCK
hints everywhere. It’s even in newly-developed code for this application.- Cursors used anytime a set of records has to be updated with a small bit of conditional logic built in. A set-based operation with appropriate CASE statements would work much better.
The primary system I deal with on a daily basis was originally developed as a DOS application and several of the above examples are drawn from it. Looking at the core tables and columns, it’s easy to identify those that began life in those early days - they all have 8-character names. Time moved on and the system grew and evolved. DOS to Windows. Windows to the web. But the database, and the practices and patterns used in the database, haven’t come along for the ride.