SQL Formatter

Input SQL
Size:0B
Lines:1
UTF-8
Formatted SQL
Size:0B
Lines:1
UTF-8

Waiting for input.

SQL Formatter Options

SQL Formatter Online Tool

As a database administrator or developer, you know that working with SQL can be a challenging task. With so many tables, columns, and clauses to keep track of, it's easy for your SQL code to become a jumbled mess. This is where an SQL formatter comes in.

This SQL formatter tool will automatically formats your SQL code, making it more readable and consistent. This can be a huge time-saver, especially when working on large projects or when collaborating with others.

One of the main benefits of this SQL formatter is that it helps to indent your code properly. This makes it much easier to see the structure of your SQL statements and to identify any errors. For example, if you forget to include a closing parenthesis, an SQL formatter will automatically highlight this mistake, making it easy to fix.

Another advantage of this online SQL formatter is that it adds whitespace to your code. This makes it easier to read and understand, especially when working with complex queries. For example, an SQL formatter might add a space between keywords and clauses, making it easier to see how the different parts of your query are related.

It will also have the ability to validate your code, checking for syntax errors and other issues. This can save you a lot of time and headaches, as it means you don't have to manually check your code for mistakes.

SQL Dialects Supported by SQL Formatter

Unfortunately, there is no one-size-fits-all SQL formatter snippet that works for all SQL dialects. Each SQL dialect has its own unique syntax and formatting rules, and a formatter that works for one dialect may not work for another.

However, this SQL formatter is designed to support 16 SQL dialects, and have options to select the formatter to work with a specific dialect. Use the SQL Formatter Options to configure it to format your code according to the specific dialect you're using (e.g. MySQL, PostgreSQL, Oracle, SQL Server, etc.).

Below are the SQL dialects supported by SQL formatter tool.

  1. Standard SQL
  2. GCP BigQuery
  3. IBM DB2
  4. Apache Hive
  5. MariaDB
  6. MySQL
  7. Couchbase N1QL
  8. Oracle PL/SQL
  9. Postgress SQL
  10. Amazon Redshift
  11. SingleStoreDB
  12. Snowflake
  13. Spark SQL
  14. SQLite
  15. SQL Server Transact-SQL
  16. Trino / Presto

Use Standard SQL as language, if you don't the specific SQL language variant.

SQL Formatter Options

By default, the beautifier is configured with Google Style guide recommendations, you can always modify and use it as per your requirement. Below are the options available in SQL Query Formatter.

  • Indentation Level - 2 Space Indent by default - The tags and contents are indented using 2 spaces.
  • Indentation Style - Allows Keywords to be left or right aligned. By default it aligns based on indentation level.
  • Comma Position - Put comma at the beginning of new line - helps to easily comment the line without change in previous keyword.
  • Keywords Text Case - Recommended to keep it uppercase.
  • Expression Width - Wraps lines at 50 characters.
  • Lines between queries - Black lines between query sections.
  • Indent inner HTML - Adds indent between <html>, </html> tags. All contents between these root tags will be indented.
  • New Lines on Conditions - Start conditional statements in new lines.
  • Dense Operators - Removes spaces before and after operators.
  • Align Aliases - Aligns columns alias

SQL Beautifier Usage

Below is the sample SQL to be formatted, just paste it in the above SQL formatter input and hit format button.

select customer_name as customer_name, city as customer_city from
(select * from customer join addresses on customer.address_id=addresses.id)
as customers
where customer_id>10
order by customer_name asc,city desc;

Below is the formatted SQL

SELECT
customer_name AS customer_name,
city AS customer_city
FROM
(
SELECT
*
FROM
customer
JOIN addresses ON customer.address_id = addresses.id
) AS customers
WHERE
customer_id > 10
ORDER BY
customer_name asc,
city desc;

SQL Formatter Features

SQL formatters typically have a variety of features that can help to make your SQL code more readable and consistent. Some common features include:

  1. Automatic indentation: This feature helps to structure your SQL code properly by automatically adding indentation to your code. This makes it easier to see the structure of your SQL statements and to identify any errors.

  2. Automatic whitespace: This feature adds whitespace to your code, making it easier to read and understand. This can include adding spaces between keywords and clauses, and between different parts of a query.

  3. Syntax highlighting: This feature highlights different parts of your SQL code, such as keywords, clauses, and strings, in different colors. This can make it easier to see the structure of your code and to spot any errors.

  4. Code validation: This feature checks your SQL code for syntax errors and other issues. This can save you a lot of time and headaches, as it means you don't have to manually check your code for mistakes.

  5. Code formatting options: This feature allows you to customize the formatting of your SQL code according to your preferences, for example to capitalize keywords, to align keywords and clauses, to format dates and numbers in a specific way.

  6. Code commenting: This feature allows you to add comments to your SQL code to explain the purpose of different parts of your code, or to leave notes for yourself or other team members.

  7. Support for different SQL dialects: This feature allows you to format your code according to the specific SQL dialect you're using, such as MySQL, PostgreSQL, Oracle, SQL Server, etc.