Dev TooloraLocal dev tools

> Formatters

SQL Formatter

Format SQL queries by dialect with readable indentation, preserved literals and configurable keyword case.

Runs locallyWorks offline
Back to results
Input

Source data

Indentation
Keyword case
Output

Result

Your result will appear here.

Tool guide

About this tool.

SQL is the language used to query and modify relational databases; a formatter makes its clauses, expressions and nested queries easier to read.

This tool changes layout and optionally keyword case without connecting to a database or executing the query.

  • Make a query from a log, ORM or database console readable before reviewing it.
  • Apply consistent indentation and keyword case to SQL in documentation, tests or code reviews.
  • Inspect joins, common table expressions, subqueries and multiple statements without replacing parameter placeholders.

Choose the SQL dialect matching your database. Standard SQL rejects dialect syntax such as $1, :name, @id or [bracketed] names.

Select 2 spaces, 4 spaces or Tabs for Indentation, and UPPERCASE, lowercase or Preserve for Keyword case.

Paste one or more statements separated by semicolons, or apply a sample, then select Run SQL Formatter. String quotes, comments and parameter placeholders stay as written.

Review the result, then copy it or save formatted.sql. If formatting fails, check the selected dialect and the syntax at the reported line and column.

  • SELECT 'from users, where id' AS note; → the quoted text stays exactly 'from users, where id'.
  • PostgreSQL: select $1::text as message, $$from users$$ as note; → keeps $1 and the dollar-quoted literal.
  • SQL Server: select [from], @id from [order] where [id]=@id; → preserves bracket-quoted identifiers and @id.
  • 2 spaces + UPPERCASE: select id,name from users; → SELECT, indented columns, FROM and an indented table name.
  • MySQL: DELIMITER // … END // … DELIMITER ; → both DELIMITER lines and the // after END stay; the semicolons inside BEGIN … END stay in the procedure.
  • select (id from users; → Could not format SQL (sql) at line 1, column 22: unexpected ";".

  • String contents and quoted identifiers are preserved; comments stay comments, including the newline ending a line comment, although comment indentation may change.
  • Keyword case applies only to recognized SQL keywords; identifiers, string values and parameter placeholders are not renamed or substituted.
  • Successful formatting is not database syntax validation, query optimization or a security check; the tool never runs a query.
  • Copy keeps the complete formatted text; Save or Download exports the same UTF-8 content as formatted.sql.
  • The supported dialects are Standard SQL, PostgreSQL, MySQL, SQLite, SQL Server T-SQL, BigQuery and Oracle SQL; choose a specific dialect for its quoting and placeholders.
  • With MySQL, DELIMITER lines are kept and each statement ending in a custom delimiter such as // is formatted on its own, so a procedure body keeps its semicolons. Other dialects reject DELIMITER. BEGIN … END bodies are not indented as blocks, and dialect-specific extensions may also require manual formatting.

FAQ

Questions about SQL Formatter

Does SQL Formatter run or validate my query?

No. It only changes layout and keyword case; the query is never sent to a database or executed. A query that formats cleanly can still contain errors your database will reject.

Why does formatting fail with Standard SQL when my query runs fine?

Standard SQL recognizes only common syntax, so dialect features such as PostgreSQL $1 placeholders, SQL Server [bracketed] names and @variables, or :name parameters cause a parse error. Choose your database’s dialect and run again.

Can I format several SQL statements at once?

Yes. Paste several statements separated by semicolons; each one is formatted on its own, with a blank line between statements.

Can it format stored procedures with DELIMITER?

Yes, with the MySQL dialect. DELIMITER lines are kept and each statement ending in the custom delimiter, such as //, is formatted on its own, so the semicolons inside BEGIN … END stay in the procedure. The body is not indented as a block, and other dialects reject DELIMITER with an error.

Is my SQL sent to a server?

No. Formatting runs locally in your browser, editor or desktop app, and the query text is never uploaded or executed.

Continue with

Text DiffAlign two texts by actual line changes, inspect both versions and export a complete comparison report.JSON FormatFormat, minify or validate JSON without rounding numbers, rewriting strings or dropping duplicate keys.JSON ↔ CSV ConverterConvert JSON records to CSV or TSV and CSV back to JSON, with quoted headers, multiline cells, leading zeros and an explicit separator.