Select Distinct Logo Clear Background

Business Analytics Blog

Automatically reformat SQL

automatically reformat SQL code with this free tool

Automatically format SQL with this great free tool

At Select Distinct we love to share tips and timesavers to help you become more efficient, and when we find great tools we love to share this knowledge

(We have no affiliation to this product or site and get no commercial benefit from it)

We found this really useful FREE online SQL formatter to help save you time

PoorSQL.com is a great free resource that we found out about from one of our clients, it takes away one of the most time intensive steps that we often come across, that is taking some badly formatted SQL and improving its formatting before you can start to understand what it is trying to do (Something that we have to do too often 🙁 )

This tool takes badly formatted SQL such as this

an example of badly formatted SQL

As you can see this is just a large block of code, with no use of spacing or indentation, making it hard to read

using the SQL formatter tool,

we can instantly get it re-formatted to this…

example output from PoorSQL.com, with reformatted SQL code

Now the code is a lot easier to read, with clearly laid out sub queries and easy to see joins

If someone came to me and asked me to help with the original code then I would have spent quite a few minutes reformatting the code to look similar to the above before I could even start to help.

Now I can drop it into the tool and get to work straight away

And more importantly, I always show people this tool as well which helps them learn to write better SQL. Improving the SQL format often goes a long to spotting their own errors too

Step by Step guide

Go to poorsql website in your browser

poorsql.com website

Copy your example of badly formatted SQL code into the “Input SQL” box

an example of badly formatted SQL

Now go to the “Formatted SQL” tab to see the code re-formatted

example output from PoorSQL.com, with reformatted SQL code

And then copy this code into your SQL editor and thats it, instantly easier to read SQL code

Customisation Options

On the right hand side are customisation options that you can optionally amend to your liking

poorsql.com customisation options

There are also plug ins, and it even works off line

Give it a try, it could save you hours. I wish I had found it earlier

Subscribe to our channel to see more tips and timesavers

Select Distinct YouTube Channel

Or find other useful SQL, Power BI or other business analytics timesavers in our Blog

Our Business Analytics Timesavers are selected from our day to day analytics consultancy work.  They are the everyday things we see that really help analysts, SQL developers, BI Developers and many more people.

Our blog has something for everyone, from tips for improving your SQL skills to posts about BI tools and techniques. We hope that you find these helpful!

Business Analytics Blog

By Simon Harrison

Simon Harrison Founder of Select Distinct Limited and a business intelligence expert