Skip to content
SQL Formatter
Live format
Input
1 lines · 58 chars
Output

The formatter does not check whether the SQL is valid.

9 lines · 68 chars
Formatted (not validated)

SQL Formatter

Format SQL for readability (does not validate or run it) — free, private and running entirely in your browser

SQL Formatter lays out a statement with sql-formatter 15.8.2. The box opens on select id, name from users where active = 1 order by name;. Output follows about 120 milliseconds later. Dialect is Standard, MySQL, PostgreSQL, or SQL Server. Keywords is UPPER or lower.

Last updated: 11 October 2026

Guide, examples, and FAQ

About SQL Formatter

What it does

format() gets that dialect, keywordCase, and tabWidth 2. SELECT, FROM, WHERE, and ORDER BY each start a line. Each column is its own indented line. UPPER writes SELECT and ORDER BY. lower writes select and order by. Quoted names and string contents stay as typed.

Who it is for

For a SQL statement you want broken on those clauses, in the keyword case on this page.

When to use it

Use it when a pasted statement is hard to scan. It does not run or optimize SQL, connect to a database, or check table and column names.

Key features

  • Dialect and keyword case

    Standard, MySQL, PostgreSQL, or SQL Server, plus UPPER or lower.

  • Two-space clause lines

    tabWidth is 2. There is no indent control and no line-break control.

  • Comments and a blank line

    A /* */ comment stays on its line. A -- comment stays at the end of its line. A second statement follows a blank line.

How to use SQL Formatter

  1. 1Leave the sample or paste SQL. Wait about 120 milliseconds.
  2. 2Choose Standard, MySQL, PostgreSQL, or SQL Server, and UPPER or lower.
  3. 3Read the output. Success says Formatted (not validated). The note says The formatter does not check whether the SQL is valid.
  4. 4Copy copies that output. Download .sql saves formatted.sql. Clear empties the input. Cmd/Ctrl+K clears only when the cursor is outside the editor.

Example

Before

select id, name from users where active = 1 order by name;

After

SELECT
  id,
  name
FROM
  users
WHERE
  active = 1
ORDER BY
  name;

Standard and UPPER. lower keeps these breaks: select, id and name on their own lines, from, where, and order by.

Benefits

  • The block comment stays put

    select 1 /* keep me */ from t; becomes SELECT, then 1 /* keep me */ indented two spaces, then FROM and t;.

  • Two statements, one gap

    select 1; select 2; becomes SELECT, an indented 1;, a blank line, then SELECT and an indented 2;.

Common use cases

  • PostgreSQL JOIN, GROUP BY, and CASE

    PostgreSQL UPPER on select u.id, u.name, count(o.id) as orders, case when u.active = 1 then 'yes' else 'no' end as live from users u join orders o on o.user_id = u.id where u.active = 1 group by u.id, u.name order by orders desc; indents JOIN under FROM, capitalizes AS, ON, WHEN, THEN, ELSE, END, and DESC, and leaves 'yes' and 'no'.

Tips & best practices

  • select id -- keep me, then a new line from users;, keeps -- keep me on the id line.
  • No SQLite or Oracle. If your dialect is missing, pick the closest of the four and check words such as TOP.
  • Spaces alone show Awaiting input, with Copy and Download off.

Common mistakes to avoid

  • Reading Formatted (not validated) as a pass. select from where still becomes SELECT, FROM, and WHERE.
  • Formatting SQL Server TOP in Standard, MySQL, or PostgreSQL. select top 10 id from users; keeps top lowercase. Only SQL Server writes TOP.
  • Expecting a rename or a reorder. PostgreSQL keeps "UserName" and 'Keep Case' in select "UserName", 'Keep Case' from "Users";. Only whitespace and keyword case change.
  • Not noticing a broken quote or comment. select 'unterminated throws. select 1 /* never ends from t; prints 1 / * never ends and warns Unclosed block comment: the output may not be valid SQL.

Frequently asked questions

Why does top stay lowercase?

Standard, MySQL, and PostgreSQL do not treat top as a keyword, so it stays on the indented line. SQL Server writes TOP.

Does Formatted (not validated) mean the SQL runs?

No. select from where still formats. The note is The formatter does not check whether the SQL is valid.

What does select 'unterminated show?

Standard shows Parse error: Unexpected "'untermina" at line 1 column 8, then that you are using the default "sql" dialect, then Select another dialect on this page: Standard, MySQL, PostgreSQL, or SQL Server. The other three keep that Unexpected line and add SQL dialect used: mysql, postgresql, or transactsql.

How are comments and two statements laid out?

1 /* keep me */ stays beside the 1. select 1; select 2; inserts a blank line between the SELECT blocks.

Does any SQL leave the browser, and what is remembered?

No. sql-formatter runs in the page. The key sql-formatter keeps the input only. Dialect and keyword case reset to Standard and UPPER on reload.

Can I change the indent?

No. tabWidth is 2. Review that two-space SQL before it goes into production code.

When another tool fits better

  • JSON Formatter. The text is JSON braces, not a SELECT list.
  • Text Diff. You want the line and word changes between two copies of a query.

Conclusion

Marks that two-space SQL result Formatted (not validated).

Ready to try SQL Formatter?

Scroll back up to start now, or continue with another free developer tool.

Guides and glossary

Learn and reference material connected to SQL Formatter.