A software package a day: SQL Pretty Printer

SQL Pretty Printer is another of those “micro” utilities that I love. If you ever have to work with “generated” SQL you know that it is rarely formatted in a useful way. Even if the SQL was hand coded, often I find the longer blocks tend to become a solid mass rather than a rationally formatted query. Enter SQL Pretty Printer. Just cut and paste a query into the program and press F2 and you now have a well formatted query that can be read without pain.

There are quite a few configuration options which set the output to be for specific databases or even blocks of code for various programming languages. I don’t suggest the latter feature. An entity framework of some type such as LLBLGen or LINQ’s Entity Objects makes far more sense to me than embedded SQL which comes with a raft of potential security problems, such as SQL Injection. Don’t allow your application to be that directly in communication with the database when modern techniques ensure proper data types and encapsulate parameters properly.

On the other hand, HTML export is wonderful when you wish to post an example to a blog. Color coded syntax highlighting isn’t standard in most development tools these days because it is unhelpful.

SELECT *
FROM   table1
       INNER JOIN table2
         ON table1.pk= table2.fk
WHERE  table1.filter = 'something'

looks a lot nicer than the monochrome equivalent. I use a web based tool online for converting C# to HTML, which is also handy when getting code onto websites.