16

I'm looking for a good T-SQL Pretty Printer so that all the code looks consistent between developers in our project. Preferably a free/open source one, but paid for isn't out of the realms of possibility as long as it's reasonably priced. Are there any particular industry leaders?

I'm not that fussed about what particular standard it uses, but the more configurable the better. That way we can have little style wars among the developers and have a bit of fun to boot. ;-)

I suppose I should add that Visual Studio and Management Studio integration would be considered favourably.

David M
  • 71,481
  • 13
  • 158
  • 186
pms1969
  • 3,354
  • 1
  • 25
  • 34
  • See also http://stackoverflow.com/questions/3310188/what-free-sql-formatting-tools-exist/3310518#3310518 – knut Sep 15 '12 at 18:25
  • See also https://stackoverflow.com/questions/401928/sql-formatter-for-sql-management-studio – w5m Apr 09 '14 at 10:49

9 Answers9

10

A free and open source alternative to the paid for options that everyone else has listed is Poor Man's T-SQL Formatter. It integrates nicely with SQL Server Management Studio. The options for configuring how the SQL is formatted are somewhat limited when compared to the other tools, but for the price it's hard to complain, and if you really want to change it, the source is available for you to tweak.

JDHnz
  • 489
  • 4
  • 10
  • 1
    There is now an online version available and a Poor Man's T-SQL Formatter plugin Notepad++. Problem solved. – wp78de Oct 23 '17 at 08:49
4

SQL Prompt has a code formatter and SSMS + VS integration

thecoop
  • 45,220
  • 19
  • 132
  • 189
  • So far, I think the most promising. I know it comes with a bit more than just formatting, but £157 for what I want (formatting) does seem a little excessive... I shall continue the search, but if nothing better comes up, I think this has it. – pms1969 Apr 08 '10 at 14:58
  • Nothing better has arrived, so Sql Prompt has it. – pms1969 Apr 21 '10 at 04:07
  • @James - Thanks - That will be useful for making sense of such monstrous queries as [this one](http://stackoverflow.com/questions/4550838/sql-server-statement-returning-values-2-times)! – Martin Smith Dec 29 '10 at 14:42
2

http://www.sqlinform.com/

The paid desktop version has a "Windows Hotkey" feature which can be used in Visual Studio.

Tomalak
  • 332,285
  • 67
  • 532
  • 628
  • Looks ok and I'll give it a try shortly, but that integration thing is quite important. I so like staying inside my little ide. – pms1969 Apr 08 '10 at 14:52
2

I can vouch for the RedGate's products, including SQL Prompt. I use several of their tools, and their support is terrific.

SD.
  • 37
  • 6
2

I had the same issue but I was looking for a command line tool. I have finally coded a Python script based on sqlparse that is a Python package mature (10+ years), still very active and aiming to parse and format SQL statements.

In post here my tiny Python script pretty_print_sql.py in case other users would be interested:

import argparse
import sqlparse

# Parse command line arguments
parser = argparse.ArgumentParser(prog="pretty_print_sql")
parser.add_argument("file", type=argparse.FileType("r"), nargs="+")
args = parser.parse_args()

# Pretty print input files
for file in args.file:
    print(sqlparse.format(file.read(), reindent=True, keyword_case='upper'))

To use it:

pretty_print_sql.py input.sql > pretty-output.sql

To install sqlparse using pip for personal usage:

python3 -m pip install sqlparse --user --upgrade

To install sqlparse using pipenv (within a project):

python3 -m pipenv install sqlparse
oHo
  • 51,447
  • 27
  • 165
  • 200
2

SQL formatter add-on for Management Studio?

Here is the one(sql pretty printer add-inf for ssms) that we are using.

James Wang
  • 453
  • 4
  • 5
0

Other than SQLinForm, Toad for SQL Server comes with an SQL formatter out of the box, among plenty of other advantages over management studio...

ercan
  • 1,639
  • 1
  • 20
  • 34
0

I have used SQLInform before for formatting code from different developers in a similar way. Works well. They now have a Notepad++ Plugin as well. enter image description here

Guido
  • 926
  • 2
  • 10
  • 19
Galwegian
  • 41,475
  • 16
  • 112
  • 158
0

Did Any one of You EMS SQL Manager for SQL Server.It's Good.

There are lots of SQL Server Managemnet Studio Alternatives

Community
  • 1
  • 1
Imrul
  • 3,456
  • 5
  • 32
  • 27
  • I like LinqPad, but that's not really suitable for what I have in mind. I need to reformat actual t-sql...... now if only sql server was entirely linq based. – pms1969 Apr 08 '10 at 14:54