Three years later, I just wanted to end this question with two options that seem to be missing, and I think they are more suitable than most of the options listed so far:
- Bad man T-SQL Formatter / poorsql.com (free, open source, SSMS add-in, command line formatting, full formatting DDL / DML script, and I am the author / maintainer, so I put it in first :))
- T-SQL Tidy (free, SSMS add-in, full DDL / DML formatting script, apparently 2008R2 add-in can do offline formatting now too - but not open source?)
I believe that any of them makes more sense than any of the previous answers, because the other options available are:
- Online-only (instant sql formatter)
- Trial / commercial software (pretty sql printer)
- Do not format (SSMS toolkit, accepted answer)
- Do not handle full T-SQL properly (CPAN module, SQL-talk prefix)
- Incomplete, process only some instructions (SqlFormat project)
source share