Skip to content
Accessibility
Theme
Text size
High contrast
Limit animations
Readable fontAtkinson Hyperlegible
Increased text spacing
Underline links
Always show focus

Runs in your browser — nothing you paste is uploaded.

SQL Formatter

Pretty-print and indent an SQL query. Pick a dialect for accurate keywords. Runs in your browser.


    

What it does

This tool takes a cramped, one-line or inconsistently indented SQL statement and pretty-prints it: keywords are upper-cased, clauses such as SELECT, FROM, WHERE and ORDER BY start on their own lines, and nested expressions are indented so the structure of the query is easy to read. It uses the open-source sql-formatter library and reformats as you type.

How it works

Pick a dialect first — Standard, MySQL, PostgreSQL, MariaDB or SQLite. The dialect controls which words are treated as reserved keywords and how dialect-specific syntax (backtick identifiers, LIMIT clauses, dollar-quoted strings, and so on) is tokenised. The formatter only rearranges whitespace and keyword casing; it never changes the meaning of your query, reorders clauses, or validates that the tables and columns exist. Your identifiers and string literals are passed through untouched.

Gotchas

  • Choosing the wrong dialect can mis-case or misalign dialect-specific syntax. If backticks or :: casts look wrong, switch dialects.
  • A syntax error in the input shows a ⚠ message instead of formatted output — fix the unbalanced parenthesis or missing quote and it re-renders.
  • It formats, it does not beautify logic: a SELECT * stays SELECT *. It is a readability aid, not a linter or optimiser.

Worked example

Paste select id,name from users where active=1 order by name and you get each clause on its own line with keywords upper-cased and the column list indented — far easier to review in a pull request or paste into migration notes. For exploring the shape of query results, pair this with CSV ↔ JSON or JSON; to compare two versions of a query, use Text Diff.

Privacy

Formatting is local; the query is never uploaded.

Frequently asked questions

Does the formatter change what my query does?

No. It only reformats whitespace, line breaks and keyword casing. It does not rewrite, optimise or validate your SQL, and your table names, column names and string literals are left exactly as written, so the query runs identically.

Why does the dialect selector matter?

Each dialect knows a different set of reserved keywords and syntax, such as backtick-quoted identifiers in MySQL or dollar-quoted strings in PostgreSQL. Picking the right one means keywords are cased correctly and dialect-specific syntax is not mangled. Standard targets generic ANSI SQL.

Can it format multiple statements at once?

Yes. Separate statements with semicolons and each is formatted in turn. If a statement cannot be parsed the tool shows an error message rather than partial output, so make sure every statement is syntactically complete.

Related tools