Articles tagged T-SQL Programming

03 January 2014
03 January 2014

Agile Database Development

Agile methodologies work well with database developments only if great care is taken to do things right. It requires good judgement and leaves little room for error. Dev Nambi, in an extract from the book Tribal SQL, argues that Agile works for smart, curious, and experienced software engineers.… Read more
17 December 2013
17 December 2013

Calculating the Median Value within a Partitioned Set Using T-SQL

It is ironic that one of the most essential of statistical aggregations, the median, has been so difficult in the past to calculate efficiently in SQL. Although the recent window functions provide the solution, there isn't an obviously superior algorithm performance-wise, particularly when working across partitioned sets. Dwain Camps sets the candidates to work and identifies the winners and losers.… Read more
31 October 2013
31 October 2013

Window Functions in SQL

SQL's windowing functions are surprisingly versatile, and allow us to cut out all those self-joins and explicit cursors. Joe Celko explains how they are used, and shows a few tricks such as calculating deltas in a time series, and filling in gaps.… Read more
09 July 2013
09 July 2013

SQL Server ALTER TABLE syntax diagrams

The words in the documentation for the ALTER TABLE syntax on MSDN are accurate with forensic precision, but the potentially-useful 'syntax diagrams' look, to the untrained eye, to be the result of someone accidentally sitting on the keyboard. The answer for ordinary mortals like us who need to understand the syntax is to have railroad diagrams as well.… Read more
11 June 2013
11 June 2013

Painless management of a logging table in SQL Server

Tables that log a record of what happens in an application can get very large, easpecially if they're growing by half a billion rows a day. You'll very soon need to devise a scheduled routine to remove old records, but the DELETE statement just isn't a realistic option with that volume of data. Hugo Kornelis explains a pain-free technique for SQL Server.… Read more
18 March 2013
18 March 2013

Solving Complex T-SQL Problems, Step-By-Step

What should you do if your first, most intuitive solution to a problem ends up scanning the data more than is necessary, resulting in poor performance? Have you missed a new SQL Server feature that can remove inefficiency from your technique? Alternatively, do you need a little help, and some lateral thinking, to open the path to a different approach? Sometimes, the answer is "both".… Read more
30 November 2012
30 November 2012

Row Sorting in SQL

It should be easy to model a game of poker in SQL. The problem is, however, that you need to model a permutation from a set of elements. Joe Celko argues that using a group of columns to do this isn't necessarily a violation of 1NF, since a permutation is atomic. Then comes the second problem: how would you sort such a column-base permutation in order? Sorting columns in SQL?… Read more
17 September 2012
17 September 2012

Matrix Math in SQL

Relational Databases have tables as data structures, not arrays. This makes it tricky and slow to do matrix operations, but it doesn't mean it is impossible to do. Joe gives the Celko Slant on how to go about doing Matrix Math in SQL.… Read more