inyourbrowser.com

SQL formatter

SQL formatter is a developer tool that beautifies SQL queries with consistent indentation and keyword casing. It supports Standard SQL, MySQL, PostgreSQL, and T-SQL dialects, handles multi-statement scripts, and outputs ready-to-copy formatted SQL. The tool runs in your browser.

Dialect:

Formatting runs entirely in your browser.

How to format SQL

  1. Paste your SQL query into the input area, minified, inline, or unstructured.
  2. Select the SQL dialect if needed: Standard SQL, MySQL, PostgreSQL, or T-SQL.
  3. Click "Format" to apply consistent indentation and keyword casing.
  4. Copy the formatted SQL for use in your query editor or codebase.

Common uses

  • Reformatting minified or auto-generated SQL to make it human-readable, similarly to how JSON formatter works for JSON data
  • Standardising SQL style across a codebase with consistent indentation and keyword casing
  • Reviewing a changed query: format the old and new versions the same way, then compare them line by line with the text diff tool

Technical specification

  • Algorithm or formula: Lexer-based formatting via the sql-formatter library. The lexer tokenises the input against a dialect-specific keyword list, then a printer re-emits with consistent indentation, line breaks around major clauses, and uppercase keywords.
  • Browser API or library: sql-formatter 15.8 (about 290 KB minified, 75 KB gzipped, including its dialect keyword lists), run in a bundled Web Worker that starts with the page. Dialects offered: Standard SQL, MySQL, PostgreSQL, and T-SQL (Microsoft SQL Server).
  • Input limits: Up to 2,000,000 characters. Memory use while parsing grows with the square of the length of a list, and, when the query cannot be parsed, with the square of the nesting depth. So the tool refuses input with more than about 10,000 statements, more than about 5,000 items in one list, such as an IN, VALUES or SELECT list (the count covers every word, value and symbol at one level of parentheses), or more than about 300 levels of nested parentheses or CASE expressions. Many statements, long lists and deep nesting add up. Formatting runs in a Web Worker, so the page stays responsive, and stops after 10 seconds. A result far longer than the input, which deeply nested parentheses can produce, is not shown. Multi-statement input (separated by semicolons) is preserved.
  • Output: Formatted SQL string in the output pane, copyable to clipboard.
  • Known limitations: The tool does not execute or fully validate the SQL; if the SQL cannot be parsed (for example an unclosed parenthesis or quote), nothing is formatted and the tool reports the line and column where parsing stopped. Vendor-specific extensions outside the chosen dialect may not be recognised as keywords. Stored procedure bodies and DELIMITER changes are not supported by sql-formatter.

Frequently asked questions

Which SQL dialects does this formatter support?
Four dialects: Standard SQL, MySQL, PostgreSQL, and T-SQL (Microsoft SQL Server). Each dialect uses its own keyword list and quoting rules for accurate formatting. All processing runs in your browser using the sql-formatter library.
Is my SQL sent to a server?
All formatting happens in your browser using the sql-formatter library. Our servers are not involved at any point.
Does it validate the SQL syntax?
The tool formats but does not execute or fully validate SQL. If it cannot parse the query, it shows the line and column of the first problem instead of formatted output.
Can I format multi-statement scripts and stored procedures?
Multi-statement scripts format well: separate the statements with semicolons and each one starts on its own line. Stored procedures are outside what the sql-formatter library supports, so a BEGIN ... END body is not indented as a block, a PostgreSQL $$ function body keeps its original lines, and a MySQL DELIMITER change can merge lines. Format the statements inside a procedure one at a time.

Related tools

Regex tester
Test regular expressions with a live match list, replace, and split modes. Runs in your browser.
YAML formatter
Format, validate, and convert YAML. Compatible with Kubernetes, CI configs, and OpenAPI files.
JSON formatter
Pretty-print, minify, validate, and sort JSON keys. Instant output.

Reviewed and tested September 30, 2026.