Format SQL code

I have been writing copious quantities of SQL lately. Some of the queries are getting really long. When I am working with Navicat it has a nice ‘SQL beautify’ feature that takes messy SQL and makes it nice and tidy. 🙂

While that features is great when using Navicat for SQL editing, sometimes I need to workdirectly with SQL Server 2008 there is no comparable feature built into Microsoft’s SQL pane. 🙁

Thankfully, with a quick copy/paste there is an online tool that can automatically format your SQL for you:

PS Normally I like NotePad++ to cleanup and format HTML but it does not seem to have that feature for SQL yet, here is the closest I could get:

Formatting SQL in Notepad++

Formatting SQL in Notepad++http://peoplesoft.wikidot.com/formatting-sql-in-notepadWell here’s an example using search-replace and regular expressions in NotePad++. The reason I’m using Notepad++ is that it seems to be better with regular expressions than most other editors.

More links about code formatting:
http://stackoverflow.com/questions/3635460/formatting-code-within-notepad
http://stackoverflow.com/questions/7871054/notepad-eclipse-sql-code-auto-indent-option
http://stackoverflow.com/questions/401928/sql-formatter-for-sql-management-studio

This gets hard to read, we need to tidy/beautify this code! :-)

This gets hard to read, we need to tidy/beautify this code! 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *