SQL Formatter
This SQL formatter takes a cramped, one-line, or inconsistently spaced query and
This SQL formatter takes a cramped, one-line, or inconsistently spaced query and
How to use SQL Formatter
- Paste or type your SQL query into the input box.
- Pick your keyword case and indentation, and the formatted query appears instantly.
- Click Copy SQL or Download .sql to save the result.
About SQL Formatter
This SQL formatter takes a cramped, one-line, or inconsistently spaced query and lays it out for readability: clauses like SELECT, FROM, WHERE, GROUP BY and ORDER BY move to their own lines, JOIN and ON indent one step under the statement, AND/OR connectors break onto indented lines, and each column in a list gets its own line. You can choose UPPERCASE, lowercase, or preserved keyword casing and pick 2-space, 4-space, or tab indentation.
It works by tokenizing your SQL first, so text inside single quotes, double-quoted or backtick identifiers, and both -- line and /* block */ comments is preserved exactly and never rewritten. Subqueries (a parenthesized SELECT or WITH) are indented as their own block, while function calls like count(x) and value tuples stay compact on one line. A quick parenthesis-balance check warns you if a bracket is unmatched.
This is a formatter, not a validator or an execution engine. It reorganizes whitespace and casing to make queries easier to read across common dialects (Postgres, MySQL, SQL Server, SQLite), but it does not check that your SQL is valid or run it. Everything happens locally in your browser: your query is never uploaded, and nothing is stored.
Frequently asked questions
- Does my SQL get sent to a server?
- No. The formatter runs entirely in your browser using JavaScript. Your query never leaves your device, nothing is uploaded, and nothing is saved after you close the page.
- Which SQL dialects does it support?
- It handles standard SQL syntax common to Postgres, MySQL, SQL Server, and SQLite, including strings, quoted identifiers, comments, subqueries, and JOINs. It formats whitespace and casing rather than parsing a specific dialect's full grammar, so dialect-specific keywords still format cleanly as identifiers.
- Will it change what my query does?
- No. It only adjusts line breaks, indentation, and the letter case of recognized SQL keywords. Text inside quotes and comments is left byte-for-byte unchanged, so the query logic stays identical.
- Can I control indentation and keyword case?
- Yes. Choose between 2 spaces, 4 spaces, or a tab for indentation, and set keywords to UPPERCASE, lowercase, or preserve their original casing. Output updates live as you change options.
- Does it validate or run my SQL?
- No. It is a formatter, not a linter or database client. It does a light parenthesis-balance check and warns on mismatched brackets, but it will not tell you if a column name is wrong or execute the query.
- Can I save the formatted result?
- Yes. Use Copy SQL to put the result on your clipboard, or Download .sql to save it as a file. Both work offline once the page has loaded.