Skip to main content
ZEKILO Dev

SQL Formatter

Paste a query and it is broken into one clause per line. Strings, names, and comments are left as they are.

Stays in your browserISO/IEC 9075 (SQL)As of 2026.10.03

Input

Press Esc, then Tab to leave the editor.

Output

How to use SQL Formatter

  1. 1Paste SQL into the input panel, or press Sample.
  2. 2Choose the dialect of your database, then the keyword case and the indent. The result updates as you go.
  3. 3Press Copy to copy the result, or Download to save it as a .sql file.

SQL Formatter options

Dialect
Standard SQL (default), MySQL, MariaDB, PostgreSQL, SQLite, SQL Server (T-SQL), Oracle (PL/SQL), or BigQuery. The dialect decides which words are keywords and which quoting styles are accepted.
Keywords
UPPER (default) writes keywords such as SELECT in capitals, lower writes them in lowercase, and Keep leaves them as typed. Table and column names are not changed.
Indent
2 spaces (default), 4 spaces, or a tab.
Minify (one line)
Joins the formatted query into one line. A line break is kept after a -- comment, because everything after it on the same line would become part of the comment.

How the formatter treats your SQL

SQL is defined by ISO/IEC 9075, but every database adds its own keywords, quoting, and operators. That is why the dialect matters. Backticks are names in MySQL and an error in PostgreSQL. Square brackets are names in SQL Server and array syntax in BigQuery.

The formatter reads the query as a list of tokens: keywords, names, strings, numbers, operators, and comments. It then writes the same tokens back with new line breaks and indentation. Each clause such as SELECT, FROM, and WHERE starts on its own line, and its contents are indented below it. Because only the space between tokens is rewritten, a string such as 'a b' keeps both of its spaces.

The formatting is done by the open-source sql-formatter library.

What it does not do

It does not parse SQL the way a database does. A query that formats cleanly can still fail when you run it, and a query with a typing mistake in a column name is formatted without complaint.

SQL Formatter examples

  • Format a query (defaults: Standard SQL, UPPER, 2 spaces)

    Input

    select id, name from users where age > 20 order by name

    Output

    SELECT
      id,
      name
    FROM
      users
    WHERE
      age > 20
    ORDER BY
      name
  • Lowercase keywords, 4 spaces

    Input

    select id, name from users where age > 20 order by name

    Output

    select
        id,
        name
    from
        users
    where
        age > 20
    order by
        name
  • Minify (one line)

    Input

    select id, name from users where age > 20 order by name

    Output

    SELECT id, name FROM users WHERE age > 20 ORDER BY name

Examples use the reference cases this tool is tested against.

SQL Formatter: frequently asked questions

Is my input sent to a server?

No. Your input and the result are processed only in this browser and are not stored. Reloading the page clears them.

Does formatting change what my query does?

No. Only whitespace, line breaks, and the letter case of keywords change. String values, quoted names, numbers, and the text of comments are copied as they are. A word that is a keyword in the chosen dialect is treated as a keyword even when you use it as a name, so its case can change with the Keywords option. Choose Keep to avoid that.

Which dialect should I choose?

Choose the database you are writing for. Standard SQL works for common queries, but backticks, square brackets, dollar-quoted strings, and some operators are accepted only in the dialects that have them.

Why do I get "The SQL could not be formatted"?

The formatter could not split the text into SQL tokens. The usual causes are a string or bracket that is never closed, or syntax that belongs to another dialect. The message shows the line and column where it stopped.

Does this tool check that my SQL is valid or run it?

No. It only arranges the text. It does not connect to a database, does not know your tables, and does not report mistakes such as a misspelled column name.

How it works · Standards

  • Processed in: this browser (your device). Nothing is sent or stored.
  • Standards: ISO/IEC 9075 (SQL)
  • Engine: sql-formatter 15.9.0 (MIT)
  • Inside a comment that spans several lines, the spaces at the start of each line are realigned. The text of the comment is not changed.
  • If joining the lines could change a string or a comment, Minify shows the formatted result instead and tells you so.
  • Long scripts take a while. Input over 64 KB is processed in the background so the page stays responsive.
  • As of 2026.10.03
  • Changelog: 2026.10.03 First release
Open-source licenses →
Something wrong with the result? Report an issue(Your input is not attached)