Data & Formats

SQL Formatter

Paste a SQL query to lay it out with each clause on its own line, indented conditions and uppercase keywords, or minify it to a single line.

Guide: Format SQL Online: Readable Queries and Risky Patterns

Ready.

Warnings heuristic

These checks look for patterns in the text. They can miss problems and can flag code that is fine. This is not SQL validation: the tool does not check that a query is valid or safe to run.

Paste SQL to check it.

    What it does

    The formatter breaks a query into readable lines: SELECT columns one per line, then FROM, JOIN, WHERE, GROUP BY, ORDER BY and LIMIT each starting a new line, with AND / OR conditions indented. Sub-queries in parentheses are indented one level deeper.

    What it leaves alone

    • String literals, quoted identifiers and comments are never changed.
    • Spacing around operators and inside expressions is kept as you wrote it, so the query means exactly the same thing.
    • Only recognised SQL keywords are uppercased; table, column and function names keep their case.

    Dialects

    The dialect list changes only how special text is read, never how the query is laid out. PostgreSQL: dollar-quoted strings ($$ ... $$, $tag$ ... $tag$) and escape strings (E'...'). MySQL / MariaDB: backslash escapes in strings and # comments. SQLite and SQL Server: [bracketed] names, and nested comments in SQL Server. BigQuery: triple-quoted and raw strings, backslash escapes and # comments. Operators such as ::, ->, ->> and || are kept exactly as typed in every dialect. Each dialect also uppercases a few extra keywords (for example TOP in SQL Server). Strings, quoted names and comments are never changed. Generic is the default and behaves as before.

    Warnings

    The warnings panel is a heuristic. It reports UPDATE or DELETE without WHERE, DROP, TRUNCATE, ALTER ... DROP, GRANT ALL, SELECT *, values joined into a query with + or left as ${...} / %s placeholders inside quotes, several statements on one line, and unclosed quotes or parentheses. Text inside strings and comments is ignored. It cannot see how your application builds the query, can flag harmless code (for example 'a' + col + 'b' in T-SQL), and does not check that SQL is valid: an empty list does not mean a query is correct or safe.

    Limits

    It uses general-purpose rules that suit standard SQL, MySQL and PostgreSQL, and it does not validate the query. Backslash escapes inside strings (a MySQL-specific feature) are not interpreted; use doubled quotes as in standard SQL. Minify removes comments.

    Example

    This one-line query:

    select u.id,u.name,count(o.id) as orders from users u left join orders o on o.user_id=u.id where u.active=1 and o.created_at>'2026-01-01' group by u.id,u.name order by orders desc limit 10

    is formatted as:

    SELECT
      u.id,
      u.name,
      count(o.id) AS orders
    FROM users u
    LEFT JOIN orders o ON o.user_id=u.id
    WHERE u.active=1
      AND o.created_at>'2026-01-01'
    GROUP BY u.id, u.name
    ORDER BY orders DESC
    LIMIT 10

    Keywords such as SELECT, FROM, LEFT JOIN, WHERE and ORDER BY are uppercased, and each starts its own line. Column and table names and the function count keep the case you wrote, the spacing inside expressions is untouched, and the string literal is never changed.

    Format or minify

    Minify does the opposite and turns a long query into a single line. The tool keeps the query exactly as you wrote it, so the line can be pasted into a log message, a configuration file or a code string without changing what the query means.

    Frequently asked questions

    Does formatting change what my query does?

    No. Only whitespace and the case of recognised keywords change. Strings, quoted identifiers and comments are never touched.

    Which SQL dialects are supported?

    PostgreSQL, MySQL and MariaDB, SQLite and SQL Server. The dialect setting changes only how special text, such as dollar-quoted strings or bracketed names, is read, never how the query is laid out.

    Does it check that my SQL is valid?

    No. It lays out the text and never runs your query, so a tidy layout does not prove that the SQL is valid.

    Is my query uploaded?

    No. It is formatted in your browser.

    Privacy

    This tool runs entirely in your browser. What you enter is processed on your device and is not sent to a server.

    Share this tool

    Your data is not included in this link.