SQL Formatter
Free SQL formatter: beautify SQL queries for MySQL, PostgreSQL and more with readable indentation. Runs in your browser.
Raw SQL
Stays in your browserFormatted SQL
Shortcuts: Ctrl+Enter run · Ctrl+Shift+C copy result · / search (use ⌘ on Mac)
Next steps
Done here? Use the Send to… menu on the result to carry it on to Text Compare or Diff Checker.
Free Online SQL Formatter & Prettifier
Paste a raw SQL query to instantly format it with clean indentation and consistent keyword casing, across ANSI SQL, MySQL, or PostgreSQL syntax. The SQL formatter lays a query out so each clause is easy to read. It is useful for database developers, analysts, and reviewers who need a readable SQL query before troubleshooting joins or sharing a migration.
Why format SQL?
SQL written on a single line, or with inconsistent indentation and keyword casing, is hard to review and easy to introduce bugs into — a misplaced condition in a dense WHERE clause is a common source of subtle query bugs. Consistent formatting makes clauses, joins, and conditions visually distinct, which matters both for your own review and for code review by teammates.
How to use this formatter
Paste your raw SQL, choose the dialect that matches your database (ANSI SQL for a generic/standard query, or MySQL/PostgreSQL if you're using dialect-specific syntax), and click Format. Keywords are uppercased and each clause (SELECT, FROM, WHERE, ORDER BY, and so on) starts on its own line with consistent indentation.
Why the dialect setting matters
SQL dialects differ in identifier quoting (MySQL's backticks vs. PostgreSQL's double quotes), available functions, and syntax extensions (like PostgreSQL's :: cast operator or MySQL's # comments). Some of these genuinely require the correct dialect to parse without error — but not every mismatch does; a few dialect-specific clauses parse under the wrong dialect without erroring and just come out mis-indented instead, so picking the dialect that actually matches your database is still worth doing even when nothing obviously breaks.
Worked example
SELECT id, name FROM users WHERE active = 1 ORDER BY name; formats to one clause per line with uppercased keywords, regardless of dialect. PostgreSQL's SELECT '5'::int; only parses under the PostgreSQL dialect — both ANSI SQL and MySQL reject it with a parse error, since :: casting is PostgreSQL-specific syntax.
Common mistakes and edge cases
- A query that's missing real content, like
SELECT FROM WHERE;, doesn't error — in practice, it formats cleanly since every keyword is valid SQL syntax on its own. A successful format isn't proof the query is complete or correct. - MySQL's
ON DUPLICATE KEY UPDATEclause parses under the ANSI SQL dialect without an error, but comes out mis-indented (confirmed by testing) rather than formatted as one clause — choose MySQL as the dialect for MySQL-specific syntax rather than relying on an error to catch a wrong choice.