Neat T-SQL tool on the web!

Want to try something in SQL Server, but don’t have a server handy where you are? Check out SQL Fiddle – it’s a kind of web scratch pad for SQL code (not just SQL Server, by the way, lots of other platforms).

This is truly a beautiful tool with separate entry panes for schema and DML statements, as well as the possibility to view or download query plans for each query. And when you’re done editing, you can copy a URL and post on online forums, in e-mails, etc, so other people can run and test your code.

Decrypting SQL objects

Ever wished you could decrypt a database object in SQL Server? The good news is, you can, even in newer versions of SQL Server! This article will take you through the basics of how to decrypt a database object, and it will hopefully give you some deeper knowledge of how encrypted objects are stored in the database, and how to access them.

Using MERGE to insert, delete and update all-in-one

As of SQL Server 2008, there’s a new powerful consolidation statement in the DML toolbox: MERGE. Using MERGE, you can perform so-called “upserts”, i.e. one statement that performs an insert, delete and/or update in a single statement. And, more importantly, with just a single join.

A short post on SQL injection.

Whenever you run dynamic SQL code from an application or in a stored procedure, make sure you clean (called “escaping” in developer-speak) all those apostrophes and semicolons, or you may find yourself on the business end of an SQL injection.

Using OUTPUT with DML statements

The OUTPUT clause allows you to combine DML statements with a kind of SELECT statement on the rows affected by the DML operation. This is a powerful way to visualize what records were touched by your statement, or an easy way to build an auditing mechanism.