Auto-formatting SQL Scripts

by Joe Havelick 7. January 2008 22:06

The importance of well formatted code can be appreciated by any seasoned professional.  This is transient across any language I've dealt with, including SQL.  Visual Studio has functionality for auto-formatting your XHTML, C#, and VB.NET code (CTRL+K, CTRL+D), but SQL Management Studio, a derivative of Visual Studio, doesn't have such a luxury for SQL/TSQL code.

Instant SQL Formatter does have a functional online formatter for neatening up your SQL script for free.  Additionally, for a price, you can download an add-in to Visual Studio, or SQL Management Studio for embedded functionality.

A number of parameters allow you to customize the result, ranging from the desired database type, to language.   This will allow you to take ugly scripts like this:

select column1, column2, column3
from table1 inner join table2 on table1.cloumn2 = table2.column2 
where value = 'false'

and turn them to this:

SELECT COLUMN1,
       COLUMN2,
       COLUMN3
FROM   TABLE1
       INNER JOIN TABLE2
         ON TABLE1.CLOUMN2 = TABLE2.COLUMN2
WHERE  VALUE = 'false'

Perhaps not an astounding example, but when applied to large, chaotically formatted scripts, it can make a huge difference.

Tags:

Tech Tips

Comments (1) -

12/28/2011 9:28:31 AM #

Priya

This online tools also is good in formating sql script
sqlserverlearner.com/.../tsql-code-formatter

Priya |

Comments are closed

About Me

Joe Havelick is a reasonable facsimile of this photo.


profile for Joe on Stack Exchange, a network of free, community-driven Q&A sites

Recommendations