views:

433

answers:

5

Does anyone know of a program, a utility, or some programmatic library, preferably for Linux, that takes an unformatted SQL string and pretty prints it?

For example I would like the following

select * from users where name = 'Paul'

be changed to something like this

select * 
from users
where
   name = 'Paul'

The exact formatting is not important. I just need something to take a large SQL string and break it up into something more readable.

A: 

This one looks good.

http://www.sqlinform.com/

There is this as well.

http://www.wangz.net/cgi-bin/pp/gsqlparser/sqlpp/sqlformat.tpl

Paul D. Eden
+6  A: 

http://www.sqlinform.com/

This tool reformats SQL code. I've used it with awesome results. It's free as a webapp and has a downloadable version as well.

GluedHands
A: 

Not that I recommend spending the (relatively large) money on it for just this purpose, but Toad has a feature built in that does exactly what you're wanting.

It includes a bunch of options allowing you to set up exactly how you want your SQL formatted (all columns on separate lines, etc.). Pretty nice, but only if you've already got Toad. I know the Oracle version does this, but I'd assume the SQL Server or other versions would as well.

BQ
A: 

Try this online formatter T-SQL Beautifier. It can also generate colorized HTML.

Ilian
+1  A: 

I enjoy using http://www.dpriver.com - it's a nice add-in to SQL Server Management Studio.

Jarrod Dixon
A pet peeve - why doesn't SSMS have code formatting by now?
Jarrod Dixon