January 20, 2017

How an SQL Beautifier Can Ease Your Coding Pain

Written by
Why is TechnologyAdvice Free?

If you don’t know what SQL is, you should probably turn back now. Actually, don’t, because you might learn something. SQL is a query language you use to CRUD (create, read, update, and delete) data within a database.

ALSO READ: Understanding Data Lake Architecture

A beautifier takes your ugly SQL text, and like a fairy godmother, turns it into something pretty that your coworkers and boss can stand to look at. These systems also transform your code into something that can be understood by its database. If your code is improperly formatted, your database may not accept it. A beautifier will check your text against the language’s standard syntax before translating. Some beautifiers will check for mistakes and refuse to translate unless your code fits, acting as a bad-code safety net.

Why You Need an SQL Beautifier

Your SQL is ugly, and no one wants to look at it.

More specifically, a beautifier makes it possible for you to transfer meaningful chunks of SQL code between users, programs, even language versions. It’ll add indentations (tabs or spaces), build out dependent lines you may not have included, and generally make SQL readable to human eyes.

Beautifiers are also helpful for teams that collaborate on their code and cobble it together after everyone does their part. Some teams use these tools to make sure their code is readable and they’re all following the same formatting without slowing down the writing process.

What to Look for in a SQL Beautifier

Like any tool, beautifiers come with different capabilities. If you don’t want to use a new tool for each type of database, you’ll need to find a full-featured solution that you can bookmark and come back to. Look for something that gives you some or all of the following capabilities:

  • Database selection tool: This helps you make sure you’re translating into the correct database. It’s not enough for a beautifier to make your code readable; it also needs to be readable by the program you’re CRUD-ing. 
  • Tabs vs. Spaces Long a divisive argument between developers of all stripes, beautifiers end this debate, at least on the translation side. Love tabs, but your boss requires spaces? First, you should congratulate your boss on being accepting of those they don’t understand, and then input your code into the beautifier. The program can translate one to the other while checking your syntax for errors.
sql beautifier: tabs vs spaces gif
  • Newline inclusion or exclusion: Again, depending on the database you use, beautifiers can include or exclude returns to fit your needs. Helpful for switching between OS, as the return vs. new line distinction can be confusing.
  • Case changes: caPitalizAtion iS iMportant. A case-changing feature will let you write without worrying about case and fix it all at once.
  • Desktop options: Most SQL beautifier tools you find online won’t transmit your code across the web, but if you’re concerned with safety, look into downloading a desktop option. You will need to update your versions as they improve, but it’s better than sending your code out where it could be intercepted.

Top SQL Beautifiers

Gudu Online Instant SQL Formatter: This one has a lot of options for beautifying, including line inclusion or exclusion, tabs vs. spaces, and more. The developers of this product also provide you with some offline options and plugins useful for beautifying in-line, embedding the tool onto your site, and working directly in your text editor. Gudu also offers several code samples to show you before and after.

DevArt SQL Formatter: This option compares the code you enter against a full database, so it doesn’t transmit your code over the net. If you’re extra concerned about security, download the desktop version and work locally. I really like all the options included here, but so many options might be confusing for a newbie. 

Dan’sTools SQL Beautify: One of many free (!!) helpful web tools over at danstools.com, the SQL Beautify tool provides fewer options than most of the others on this list, but simplicity is part of the charm. Dan’s Tools also provides a minified text beautifier that cleans up and makes your minified SQL easier to read, so you can check it before you transmit.

GitHub options: Because beautifying SQL (and other languages) is so popular, there are 20 GitHub repositories you can access and use to install a beautifier on your machine. These options take all forms, and many of them can update more than SQL —  including Ruby, JSON, and CSS.

FreeFormatter.com: This site offers tools to help you beautify, format, minify, and translate SQL. Each of these tools will help you make your code, of any language, easier to read and ready to transmit to your database or site. Go there. You’ll be impressed.

* * *

Writing in SQL is hard, but a beautifier can make it a little easier, especially when you collaborate. These tools are by no means the only options out there, but they represent a good cross-section of the types of tools and capabilities available. Are there any helpful features or tools we missed? Let us know in the comments. 

Free Download

Guide To Data Warehousing

Get My Free Guide
Technology Advice is able to offer our services for free because some vendors may pay us for web traffic or other sales opportunities. Our mission is to help technology buyers make better purchasing decisions, so we provide you with information for all vendors — even those that don't pay us.