T-SQL Prettifiers

Rate This
  • Comments 1

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:

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

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!

 

Leave a Comment
  • Please add 1 and 7 and type the answer here:
  • Post
  • These tools are good, but a prefer Devart's products. The new version of <a href="www.devart.com/.../">SQL Complete</a> (with enhanced functionality of SQL Formatter) is the best choice for formatting using SQL.

Page 1 of 1 (1 items)