http://www.sqlservercentral.com/blogs/sql_awesomesauce/2012/12/10/great-tools-for-formatting-t-sql/ Printed 2015/04/01 05:18AM
Great Tools for Formatting T-SQL
For the month of December, I’ll be taking a little holiday from blogging. In the meantime, enjoy a few of my more popular golden oldies, like this one (original post here: http://wp.me/pZM1Z-FE). And be sure to drop by our live weekly webshow, DBAs@Midnight, at 11pm Central time on Fridays!
I have a big rant I add to….well, to every single SQL session I give. That rant is on formatting code. You see, (I say,) you can’t even begin to understand or optimize a query if it’s not formatted…and by “formattted”, I mean breaking out query clauses onto different lines, indenting column lists, etc etc.
Along with this speech, I normally give out a few resources for easier code formatting – after all, no one wants to go through every stored procedure, view, and trigger and format it by hand. In order of preference (most favorite down), here are those tools:
- Red-gate’s SQL Prompt – CTRL-K-Y formats all the code in your query window in a single go, as long as it’s parsable (no syntax errors). I cannot recommend this tool enough. It’s beautiful.
- Poor SQL Parser – This free online utility lets you copy-paste your code into and out of a window and format it. I haven’t yet downloaded the free version, but I’ll update you here when I do. Thanks to Brent Ozar for the link Friday (and thereby for the blog post inspiration)!
- SSMS ToolsPack – This won’t format the code (in its current version), but it changes all keywords to uppercase (e.g., select to SELECT). This is handier than you’d think.
- MS Word Macro – You can grow your own copy-and-paste-and-format utility with MS Word utilities, or you can use the SQL formatting macro code I supplied for you here.