Format and beautify SQL queries with various styles and conventions
Anyone who has scrolled through a 400-character SQL query jammed onto a single line knows the pain this tool solves. A stored procedure export, a query copied from a Slack thread, or a minified statement pulled from an application log often arrives with no line breaks, inconsistent capitalization, and clauses packed together in a way that makes it nearly impossible to spot a missing JOIN condition or a misplaced parenthesis. The SQL Formatter takes that raw text and rebuilds it into a properly indented, readable query so you can actually see its structure — SELECT list, FROM, WHERE, GROUP BY, and nested subqueries each landing on their own visually distinct block.
Paste or type a query and the output updates as you type: in the Standard style SELECT, FROM, WHERE, GROUP BY, ORDER BY and HAVING each start a new line, JOINs break onto their own lines, each column in the SELECT list gets its own line, and every parenthesis indents its contents one level so subqueries stand out. Expanded also breaks after every comma, while Compact only wraps at the maximum line length. You choose keyword case (UPPERCASE, lowercase or Title Case), spaces or tabs, the indent width, and whether comments are stripped. It is a lightweight tokenizer rather than a full SQL parser, so it formats standard SELECT, INSERT, UPDATE and CTE queries well but does not know dialect-specific syntax; the Oracle, MySQL, PostgreSQL and SQL Server presets currently produce the same layout as Compact.
Formatting happens in your browser, so the query text is not sent anywhere — which matters when the SQL contains internal table names or business logic. Your settings, and the last 20 queries you copied, are kept in local storage; Clear History removes them. A common workflow is formatting a query before a code review or before adding it to a migration file, since consistent indentation makes diffs in version control far easier to read than one squashed onto a single line.
Turn a dense or minified SQL query into a cleanly indented, readable statement.
Copy the query from your database client, log file, or codebase and paste it into the input box.
Choose Standard for one clause per line, Expanded to also break after every comma, or Compact to keep clauses together and wrap only at the maximum line length.
Under Advanced Settings, set keyword case, spaces or tabs, indent width and maximum line length. The formatted output updates automatically about half a second after each change.
Read through the output before using it: check that subqueries are indented as expected and that nothing dialect-specific (backslash escapes, dollar-quoted bodies) was rearranged.
Copy the cleaned-up query and paste it back into your SQL file, migration script, or code review.
SELECT, FROM, WHERE, GROUP BY, ORDER BY and HAVING each start a new line, and with Align Columns on, every comma in the SELECT list starts a new line too.
Each open parenthesis adds one indent level, so the inner query sits one step in from the outer one.
Compact only wraps when a line passes Max Line Length (80 by default). The Oracle, MySQL, PostgreSQL and SQL Server styles currently produce this same compact layout.