Folks, is there a tool to format/indent SQL Server queries in query window ?
Asked
Active
Viewed 1.7k times
4
-
1There should be same option like we have in visual studio built in. Ctrl + K + D – Kamran Shahid Jan 17 '11 at 07:10
4 Answers
8
With Apex SQL Refactor, you can specify your formatting preferences and reformat selected code or the entire window at any time using a keyboard shortcut. There's a free version.

srmark
- 7,942
- 13
- 63
- 74
6
+1 to JackM.
Just add a mention for some other (not free) tools available from Red Gate, depending on exact requirements.
Might be something you'd be interested in.

AdaTheDev
- 142,592
- 28
- 206
- 200
2
Older question which has much more activity and more answers: SQL Formatter for SQL Management Studio
My contributon to this mess is Poor Man's T-SQL Formatter / http://poorsql.com - free, open-source, does bulk formatting from command-line, SSMS plugin, etc, and (in theory) handles all SQL syntax up to SQL Server 2008 (R2).