Online sql formatter




Earlier this year we wrote about an online syntax highlighter that could take a block of code and format it in a way that makes it easier for people to read. While it worked with a lot of various programming languages it doesn’t have as many customization options as I would like it to have when sharing SQL database queries with other people. After some searching around I found the Instant SQL Formatter which supports MSSQL, MySQL, Oracle, and several other SQL query formats.

With this tool you’re able to take a very poorly formatted query and not only have the syntax highlighted but also have the format adjusted so that it is optimized for easy reading. You can also have it take a query and build code for a multitude of different programming languages. So if someone sends you a SQL query that you need to use in your PHP-based website you can drop it into this service, select PHP as the output, and it will spit out the PHP code needed to build the query. If you just want to share the query on a website you can grab the HTML output which retains all of the formatting you see in the example output. Pretty slick.

Here is an example of some poorly formatted SQL code that I used in the screenshot above and had converted to HTML:

SELECT TOP 100 sl.specobjid,
               sl.lineid,
               sMax.maxvel
-- get the spectroscopic object ID, the line ID, and the max width (in velocity)  
FROM   specline sl,
       (SELECT specobjid,
               lineid,
               Max(2.99e5 * 2.354 * sigma / wave) AS maxVel
        FROM   specline
        WHERE  (
               -- only include measured lines  
               category = 2
               AND
               -- only include the most prominent lines  
               lineid IN ( 1215, 1400, 1549, 1909,
                           2799, 4863, 6565 )
               AND
               -- make sure that this is a reaonably well measured line  
               -- (these are fairly weak constraints)  
               nsigma > 3
               AND chisq / nu < 20
               AND ew > 0
               AND Abs(ew  height * sigma * 1.065 * 2.354 / continuum) / ew <
                   0.25 )
        GROUP  BY specobjid,
                  lineid) AS sMax 

Instant SQL Formatter Homepage