SQL Formatter

Paste a SQL query or script and get it back with clauses on separate lines, consistent indentation and the keyword case you prefer. Pick the dialect so that dialect-specific syntax (backticks, brackets, :: casts) is understood. The SQL is only reformatted: it is never executed, never sent to a database and never uploaded.

Processed locally in your browser. Your data is not uploaded to our servers.

Your SQL stays in this page: it is never run, uploaded or sent to analytics.

Choose the database you write for. Standard SQL works for many simple queries. SQL Server queries (names in square brackets such as [Login], CROSS APPLY, GO) need SQL Server (T-SQL).

SettingsDefault settings

Result

Examples

Before and after, with uppercase keywords:

BeforeAfter
select id,name from users where active=1SELECT id, name FROM users WHERE active = 1
select * from a join b on a.id=b.idSELECT * FROM a JOIN b ON a.id = b.id

Formula & Methodology

The SQL is split into tokens (keywords, names, numbers, strings and comments) by the maintained โ€œsql-formatterโ€ library, using the grammar of the dialect you choose, and then printed again with line breaks and indentation. Only whitespace and, if you ask for it, the case of keywords change; strings, names and comments are kept as written.

This tool formats text. It does not run, check or optimise queries, and it knows nothing about your schema.

Notes and limitations

  • The SQL is never executed or sent to a database, even for destructive statements such as DROP or DELETE.
  • The dialect matters: syntax from another dialect may be rejected or formatted oddly. Try Standard SQL if your dialect is not listed.
  • SQL Server scripts: choose SQL Server (T-SQL). Only in that dialect are [bracketed] names, CROSS APPLY and OUTER APPLY read, and a GO line (with an optional repeat count such as GO 5) is kept on its own line as a batch separator. The tool only reformats; it does not run or check the script.
  • The formatter reports text it cannot tokenise (for example an unclosed string) but does not validate that a query is correct for your database.
  • Texts up to 150,000 characters are formatted. Extremely deep nesting is refused instead of freezing the page.
  • Comments are kept in place. Very unusual vendor extensions can be formatted differently from your teamโ€™s style guide.

How to Use

  1. Paste your SQL into the box.
  2. Choose the SQL dialect, the indentation and the keyword case.
  3. Read the formatted result. If the SQL cannot be read, the message shows the line and column.
  4. Copy the result or download it as a .sql file.

Frequently Asked Questions

Is my SQL executed or sent anywhere?

No. It is only reformatted as text in your browser. It is never run, never sent to a database and never uploaded to ToolQuarter, analytics or any other service.

Which SQL dialects are supported?

Standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server (T-SQL), Oracle (PL/SQL), BigQuery, Snowflake and Redshift. The dialect decides which syntax is understood.

Why does the formatter say it could not read my SQL?

Usually there is something it cannot tokenise, such as an unclosed quote, a stray symbol or syntax from a different dialect. The message gives the line and column; try another dialect or fix that spot.

Does formatting change what my query does?

No. Only whitespace, and optionally the case of keywords, change. Strings, names and comments are left as written.

Can I minify SQL with this tool?

This tool beautifies SQL. Minifying safely needs a full parser for every dialect, so it is not offered here.

Last updated: