Great Tools for Formatting T-SQL

, 2011-09-12

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:

  1. 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.
  2. 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)!
  3. 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.
  4. 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.

Happy days,

Jen McCown





Related content

Database Mirroring FAQ: Can a 2008 SQL instance be used as the witness for a 2005 database mirroring setup?

Question: Can a 2008 SQL instance be used as the witness for a 2005 database mirroring setup? This question was sent to me via email. My reply follows. Can a 2008 SQL instance be used as the witness for a 2005 database mirroring setup? Databases to be mirrored are currently running on 2005 SQL instances but will be upgraded to 2008 SQL in the near future.


1,567 reads

Networking - Part 4

You may want to read Part 1 , Part 2 , and Part 3 before continuing. This time around I'd like to talk about social networking. We'll start with social networking. Facebook, MySpace, and Twitter are all good examples of using technology to let...


1,530 reads

Speaking at Community Events - More Thoughts

Last week I posted Speaking at Community Events - Time to Raise the Bar?, a first cut at talking about to what degree we should require experience for speakers at events like SQLSaturday as well as when it might be appropriate to add additional focus/limitations on the presentations that are accepted. I've got a few more thoughts on the topic this week, and I look forward to your comments.


360 reads