SQL Formatter

    Format, beautify, and minify SQL queries.

    Input
    Output
    SELECT * FROM users WHERE created_at > '2023-01-01' AND status = 'active' ORDER BY id DESC LIMIT 10

    How to Use

    1. 1

      Input SQL

      Paste your raw query, upload a file, or import from URL.

    2. 2

      Select Dialect

      Choose PostgreSQL, MySQL, T-SQL, or Standard SQL for correct syntax highlighting.

    3. 3

      Format or Minify

      Use the toolbar buttons to beautify or compress your SQL code.

    SQL Formatting and Dialects

    This SQL formatter rewrites a query with consistent line breaks, two-space indentation and uppercase keywords, and it can also minify a query onto a single line.

    Supported dialects

    Pick the dialect that matches your database so its specific syntax parses correctly. For example, PostgreSQL :: casts and T-SQL [bracketed] identifiers fail under Standard SQL.

    • Standard SQL
    • PostgreSQL
    • MySQL / MariaDB (formatted with MySQL rules)
    • Microsoft T-SQL (SQL Server)
    • PL/SQL (Oracle)

    Multiple statements are separated by two blank lines. If the query can't be parsed in the selected dialect, the tool shows an error and leaves your SQL unchanged.

    When formatting helps

    SQL copied from application logs, ORMs and query builders usually arrives as one long line. Breaking it into clauses makes it easier to spot a missing join condition, compare two versions in a code review, or paste a readable query into documentation.

    Caveats

    • Minify collapses whitespace and deletes -- line comments with a text pattern, not a parser. A -- inside a string literal such as 'a--b' is treated as a comment and the rest of that line is removed. /* block */ comments are kept.
    • Neither button checks that a query runs; test it against your database.
    • Formatting does not make SQL safe. Use parameterized queries instead of building SQL strings from user input.

    Frequently Asked Questions

    Formatted SQL is critical for readability and debugging, visualizing clause logic.

    Yes, all processing happens in your browser. No data is sent to any server.

    Related Tools