SQL & Databases

SQL Formatter

Format and minify SQL for a dozen dialects with configurable style.

  • History kept on this deviceRecent results are kept in this browser's local storage until you clear them.
  • Runs in your browserProcessing happens in this page. No application server receives your input.
More options

SQL input

Formatted or minified SQL

What this tool does

Formats SQL across eighteen dialects with configurable keyword casing (upper, lower, or preserve), indentation width (2 or 4 spaces), and parenthesized expression wrapping width, or minifies a multi-line script down to a single line on the main thread without contacting any server or starting a database engine.

For example, formatting select id,name from users where id in(1,2,3) with dialect postgresql and uppercase keywords places SELECT, id,, and name on separate lines, followed by FROM users, WHERE, and the IN list wrapped at the configured expression width.

Dialect-aware minification

Minifying SQL with a naive whitespace regular expression corrupts string literals and treated -- inside a string as a line comment. This tool uses a linear, non-backtracking scanner that preserves every space and newline inside single-quoted string literals (including '' escapes and MySQL \' escapes), dialect quoted identifiers ("...", `...`, and [...]), and PostgreSQL $tag$...$tag$ dollar-quoted bodies, while stripping -- line comments and /* ... */ block comments (nested in PostgreSQL, non-nested in MySQL).

Limits

Formatting is lexical: it does not validate, and SQL that no engine would accept still formats. Dialect selection changes tokenization, not semantics: formatting Postgres SQL as MySQL is allowed and will quietly move a :: cast. Minification is whitespace and comments only; it does not shorten identifiers or rewrite the query.

Scope: this covers the page itself. Your browser, operating system, clipboard, downloads, extensions, and crash recovery may keep copies, and a compromised site origin would not be protected.