Convertur

SQL formatter and beautifier

SQL formatter that puts each clause on its own line, fixes indentation and uppercases keywords. Works with common SQL dialects. Runs in your browser.

Loading tool...

How to format SQL

Paste a query into the input pane and click Convert. The sql-formatter library parses it in your browser and lays it out with SELECT, FROM, WHERE, JOIN, GROUP BY and the other clauses each on their own line, two-space indentation for columns and conditions, and keywords in uppercase. Copy the formatted SQL back into your editor, migration or pull request.

Why format SQL

Consistent formatting makes reviews faster and diffs smaller. Complex joins and subqueries are much easier to follow when the whole team writes them the same way.

Dialect support

It uses the general SQL grammar from sql-formatter, which covers the common syntax of PostgreSQL, MySQL, SQLite, SQL Server and similar databases: CTEs with WITH, subqueries, window functions, CASE expressions and multiple statements separated by semicolons. Vendor-specific syntax, such as PostgreSQL's :: casts or T-SQL brackets, may format less neatly. Comments are kept where they are.

A quick example

A one-line query such as select id, name from users u join orders o on o.user_id = u.id where o.total > 100 order by name comes out with SELECT on its own line, id and name indented below it, then FROM users u, JOIN orders o ON o.user_id = u.id, WHERE o.total > 100 and ORDER BY name, each starting a new line. The meaning of the query doesn't change.

Before you start

Input: SQL. Output: Formatted SQL. The settings appear before anything runs, so you can check them first. Your original file is never changed.

The value you enter is processed in your browser. Still test the output where it will be used. Clean formatting does not prove the data is safe or correct.

Keep the original until you have opened and checked the result. The work happens in this browser tab, so the size you can handle depends on your device's memory, your browser and the file itself.

How to use the SQL formatter and beautifier

  1. Paste your SQL query into the input pane.
  2. Click Convert to format it.
  3. Check the formatted output.
  4. Copy it back into your editor or migration file.

Last updated · How we build and check tools · Report an error

Learn more

Related tools

SQL Formatter FAQ