Posted by
Andrew Gould
on 27 November 2013
Triggers are special stored procedures that execute automatically in response to certain events in a database. This blog explains how to create three types of trigger in SQL Server: DML, DDL and Logon triggers.
Posted by
Andrew Gould
on 11 October 2013
This blog examines how to use Transactions in Microsoft SQL Server to allow you to control when data changes are committed to the database. You'll also discover how you can rollback transactions, effectively giving you the chance to undo changes to your data.
Posted by
Andy Brown
on 06 June 2013
This blog gives the low-down on how to start and use the debugger included in SQL Server Management Studio 2008 R2 and SSMS 2012.
Posted by
Andrew Gould
on 08 May 2013
This blog teaches you how to modify existing data in your database by either deleting records or updating them.
Posted by
Andy Brown
on 03 May 2013
You can use BEGIN TRY to trap errors from SQL Server 2005 onwards, and also raise your own errors using RAISERROR or THROW - this blog explains all!
Posted by
Andy Brown
on 03 May 2013
For the sake of completeness, this blog explains how to join to the results of table-valued functions (like a correlated subquery on steroids).
Posted by
Andrew Gould
on 26 April 2013
This blog teaches you how to return values from your SQL stored procedures using two different techniques: return codes, and output parameters.
Posted by
Andrew Gould
on 22 April 2013
Dynamic SQL is a technique for building valid SQL statements from separate pieces of text. You can use this technique to create remarkably flexible and useful queries, as long as you're aware of the potential danger of SQL injection attacks.
Posted by
Andrew Gould
on 08 April 2013
A derived table is a technique for creating a temporary set of records which can be used within another query in SQL. You can use derived tables to shorten long queries, or even just to break a complex process into logical steps.
Posted by
Andrew Gould
on 26 March 2013
Cursors allow you to step through a set of data one record at a time. They’re not the quickest tool in SQL Server’s box, but they have their uses and this blog explains how they work.
Posted by
Andrew Gould
on 18 February 2013
Many programming languages feature a variety of types of loop which allow your programs to repeat a set of instructions multiple times. In SQL there is only one type of loop, and this blog explains how it works!
Posted by
Andy Brown
on 08 February 2013
This blog shows you how to create table-valued functions in SQL (ie functions which return a table of data!).
Posted by
Andy Brown
on 08 February 2013
Table variables allow you to hold rows of data in temporary storage, without any processing overhead. Read this blog to add this technique to your SQL armoury!
Posted by
Andrew Gould
on 04 February 2013
While SQL Server Management Studio is a powerful tool for writing queries, it has absolutely no concessions towards making the results of those queries remotely presentable! This blog describes several techniques for getting the results of a query into another application so that you can format them to your heart’s content.
Posted by
Andrew Gould
on 01 February 2013
If you have a calculation that you frequently use in SQL queries you're probably bored of writing out the same code time after time. Why not try creating a user-defined function to save you the hassle? This blog teaches you how to define your own custom functions, including how to use input parameters, how to alter a function after you've created it, and even how to use fancy programming techniques such as variables and IF statements to help structure complex sequences of calculations.
Posted by
Andy Brown
on 28 January 2013
You can use the IF statement to test conditions in SQL - this blog explains how, and also explains why you might prefer to use CASE WHEN instead.
Posted by
Andrew Gould
on 28 January 2013
If you’ve been writing SQL queries for a while you’re probably fairly confident with writing single SELECT statements to return a set of records. If you’re ready for a bit more of a challenge, this blog will teach you how to nest one SELECT statement inside another in order to create a subquery. If you’re thinking “that sounds simple enough” then you might want to read to the end of this series, where we’ll attempt to melt your brain by explaining correlated subqueries!
Posted by
Andy Brown
on 28 January 2013
SQL comes complete with a few useful global variables, giving you information such as the row number of the record just inserted, or the number of rows affected by a query. Here's how to use them!
Posted by
Andrew Gould
on 16 January 2013
When you write queries in SQL it's immensely useful to be able to show records matching criteria that you've set. You can do this using the WHERE clause and this blog teaches you how to use it!
Posted by
Andy Brown
on 03 January 2013
Variables in SQL always begin with @, and allow you to program more efficiently. Learn the tips and tricks in this short series of blogs!