SQL formatter
Paste a query to lay it out clearly, or squeeze it onto one line.
About SQL Formatter
Long queries are hard to review when they sit on a single line. This formatter reads your SQL with its own tokenizer, so strings, quoted names and comments are left alone, and then lays out the clauses: one major clause per line, one column per line in long lists, indented subqueries and common table expressions, and AND or OR conditions underneath each other. Minify mode strips comments and extra spaces. It follows common SQL used by MySQL, PostgreSQL, SQLite and SQL Server, and it does not run your query.
- Reviewing a long query from an ORM log or a slow query report.
- Tidying SQL before you paste it into a pull request or a ticket.
- Shrinking a statement to one line for a config file or a URL.
- Making the layout of a team's queries the same.
How to use SQL Formatter
Step 1
Paste your SQL and pick Format or Minify.
Step 2
Choose upper case, lower case or as typed for keywords, and the indent.
Step 3
Copy the result or download it as a .sql file.
Good to know
- The dialect is generic. Procedural code such as stored procedures, PL/SQL blocks and T-SQL control flow is spaced but not understood, so check those by eye.
- Minify keeps optimizer hints and MySQL's special conditional comments, because removing them can change what the query does.
- Formatting never changes names or values. Only spaces, line breaks and keyword case change.
Common questions
Does it work for MySQL, PostgreSQL and SQL Server?
It handles the syntax they share, plus backtick, double-quote and square-bracket names, PostgreSQL casts and dollar-quoted strings, and ? or :name parameters. Vendor-only statements are kept but may be spaced plainly.
Is my SQL sent anywhere?
No. The formatter runs in your browser and your query is not uploaded.
Why did it not change my keyword that is also a column name?
Words that are common column names, such as name, date, type and key, are left as you wrote them, to avoid turning a column into capitals by mistake.