Free T-SQL Formatter

If you are working on a project that has a lot of SQL code and wish you could reformat it to make it more readable, I just stumbled on a slick utility that is being developed in C# by Tao Klerks named Poor Man’s T-SQL Formatter.  It can be found here:  http://www.architectshack.com/PoorMansTSqlFormatter.ashx  It’s not finished yet, but has enough functionality to be truly useful.  Tao tells me he is working on refactoring the code to make it more maintainable and adding more formatting options.

It has plug-ins for SQL Server Management Studio, and WinMerge, and a command line version that will allow you to integrate it into other tools like Beyond Compare thanks to a new -output command line option Tao recently added just for this purpose.

 

Here’s how I set it up for Beyond Compare 3:

In Beyond Compare 3, select the Tools | File Formats menu

Create a new Text Format named SQL Tidied

Mask: *.sql

Conversion: External program (Unicode filenames)

Loading: {path to PoorMansTSLFormatter}\SqlFormatter.exe -o "%t" "%s"

You probably want to move it in the list of formats to be just below the built-in SQL format so that it doesn’t get chosen automatically every time you compare SQL files.

 

Now you can compare two different SQL files after normalizing them to common “tidy” format which lets you see the true differences, and ignore unimportant ones like whitespace, wrapping etc.

No Comments