T-SQL Prettifiers

OK, I don't think that's even a word, but the synonyms (can a non-word have a synonym?) are code beautifiers, sql formatters, etc. The basic idea is that it's a program that re-formats the text in a Transact-SQL statement using a standard set of rules. They do things like capitalizing keywords or breaking lines and adding tabs. For instance, they turn this:

select name, address, city, state, zip, employer from
employee inner join employers on employee.id = employer.employeeid where name like 'Buck' and salary = 'A quadrillion dollars'
order by lname

Into this:

FROM employee 
INNER JOIN employers 
ON employee.id employer.employeeid 
WHERE name LIKE 'Buck' 

AND salary 'A quadrillion dollars'
ORDER BY lname

Why use these tools? Well, I just find the second set of code easier to read. And if it's easier to read, it's easier to catch mistakes and tune, at least for me. There are various versions of this - I use this one on the web: http://www.simple-talk.com/prettifier/default.php, as well as their client software (you pay for this one): http://www.red-gate.com/products/SQL_Refactor/index.htm, and I've also used this one: http://www.dpriver.com/pp/sqlformat.htm, and it's pretty good. There are also even beautifiers and reformatters that you can install in SSMS, althought I've had mixed results with these.

So get out there and get that code cleaned up. Most of it is as messy as a teenager's room!


Comments (1)
  1. Sergei says:

    These tools are good, but a prefer Devart's products. The new version of <a href="http://www.devart.com/…/">SQL Complete</a> (with enhanced functionality of SQL Formatter) is the best choice for formatting using SQL.

Comments are closed.

Skip to main content