views:

145

answers:

3

Can you please point me to a an SQL code formatter, preferably as an opensource library for NET?

I need to make sql source code invariant to the formatting, because i would like to make consistent diff on version control system merges, and it's not easy to maintain in generated code mixed with snippets of handcrafted code.

My idea is to plug code formatter at the end of generation process for each file.

+1  A: 

In my answer to this question, I mentioned C# Code Format for formatting C#, but it does also support sql. The source code is available from here. (I've never used it myself though, so cannot comment on its highlighting quality.)

Additionally, there is SQL Pretty Printer, but this is a paid-for library.

adrianbanks
A: 

I've been really disappointed with the SQL formatters out there, both paid-for and open-source. Sooner or later they break down with very complex T-SQL, especially the new common table expressions. There's commercial replacements for SSMS like Quest Toad for SQL Server, but their formatting engines can't be called from the command line or as libraries.

Brent Ozar
A: 

If you put the fomatter inside the SSMS code editor(use macro to control the sql layout), things can be easier, but it's just the solution for simple SQL statement, if To XML or complicated clause, this might be a major pain.

mareinke