Skip to content
Guide · SQL tools

SQL Formatter & Beautifier (Free Online Tool)

Paste a long or messy query, press Format SQL and get it back with one clause per line, consistent indentation and the keyword case you choose. This SQL formatter runs the open-source sql-formatter library in your browser, so your SQL is never uploaded.

Formats SQL in your browser with the open-source sql-formatter library. Nothing is sent to a server.

Examples:
Facts on this page checked 8 October 2026 against the official documentation. Versions covered: sql-formatter 15.9.0. Next review due April 2027. The playground runs entirely in your browser; nothing you type or open is sent to CodeWithSQL.
Short answer
  • Formatting is done by sql-formatter 15.9.0, an MIT-licensed JavaScript library, running in your browser.
  • Ten dialects: Standard SQL, MySQL, MariaDB, PostgreSQL, SQL Server (T-SQL), Oracle (PL/SQL), SQLite, BigQuery, Snowflake and Redshift.
  • Options: keywords in UPPER, lower or as typed, and indentation of 2 or 4 spaces.
  • It changes layout only; it does not check that the query is valid or run it. Stored procedures are not supported by the library.
How we know: Written from the playground's own code and the sql-formatter project's README on GitHub, checked on 8 October 2026. The before and after example on this page is the output of the formatter with its default settings.

How to use the SQL formatter

  1. Paste your SQL into SQL to format, or press an Examples button.
  2. Choose the Dialect your query is written for. Each database has some syntax of its own, and the dialect tells the formatter which to expect.
  3. Set Keywords (UPPER, lower or as typed) and Indent (2 or 4 spaces).
  4. Press Format SQL or Ctrl+Enter (Cmd+Enter on a Mac). The result appears under Formatted SQL; Copy result copies it to the clipboard.

After the first format, changing any of the three options reformats the query straight away, which is a quick way to compare styles.

Before and after

The Messy SELECT example, formatted as Standard SQL with UPPER keywords and 2-space indentation. Each clause starts a new line, and function names such as count keep the case they were typed in: the Keywords option changes keywords only.

Input: one long line
select c.name,count(o.order_id) as orders,sum(o.total) spent from customers c join orders o on o.customer_id=c.customer_id where o.order_date>='2026-01-01' group by c.name having sum(o.total)>100 order by spent desc
Output of Format SQL
SELECT
  c.name,
  count(o.order_id) AS orders,
  sum(o.total) spent
FROM
  customers c
  JOIN orders o ON o.customer_id = c.customer_id
WHERE
  o.order_date >= '2026-01-01'
GROUP BY
  c.name
HAVING
  sum(o.total) > 100
ORDER BY
  spent DESC

What the SQL beautifier changes, and when it helps

As the example shows, each main clause (SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY) starts its own line with its contents indented beneath it, each selected column gets a line of its own, joins stay under FROM, and operators such as = and >= get a space on each side. Nothing else about the query changes: names, values and the order of clauses stay as you wrote them.

That layout is most useful when you read SQL you did not write: a query copied from an application log or an ORM's debug output, a long report query shared in a chat, or a change you are reviewing. Formatting both versions of a query the same way before comparing them also makes the real differences easier to spot.

Limitations

  • No validation. The formatter rearranges whitespace and keyword case. A query with a wrong column name formats without complaint; run it in the online SQL editor or PostgreSQL playground to check it.
  • Stored procedures. The library's README says it does not support stored procedures, or changing the statement delimiter to something other than a semicolon. Format the queries inside a procedure separately.
  • Input it cannot read. If the formatter cannot parse the text for the chosen dialect, the status line shows the error and the output is left unchanged. Picking the right dialect often fixes it.
  • One style. Only keyword case and indent width are adjustable here, although the library has more options.

Privacy: your SQL is not uploaded

The formatter library is loaded from this site and runs on your device. The SQL you paste and the formatted result stay in your browser and are not sent to CodeWithSQL or anyone else, which matters when a query contains table names or values from work.

Writing SQL that is clear to begin with is a skill in itself: practise it with the SQL exercises and the SQL beginner course.

Frequently asked questions

Is this SQL formatter free?

Yes. There is no account or limit, and the sql-formatter library it uses is open source under the MIT licence.

Which dialect should I choose?

The database the query runs on. Standard SQL works for most simple queries; choose the specific dialect when the query uses syntax only that database has.

Does it fix errors in my SQL?

No. It only changes layout and keyword case. To find errors, run the query against a database.

Can it format PL/SQL or T-SQL procedures?

Queries in those dialects, yes. Whole stored procedures are outside what the library supports, so results for procedure bodies may be poor.

Sources

Checked 8 October 2026.

How we research tool pages: our editorial method. The engines are open-source projects credited on each page.

Want structured practice?

Work through real problems with hints and solutions, or follow the beginner course.